Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Chatting Java Room + Private (lanjutan dari Class SERVER)

Lanjutan class Server


class clientThread extends Thread{                
 
BufferedReader is = null;
PrintStream os = null;
Socket clientSocket = null;
clientThread t[];
String name;
 
public clientThread(Socket clientSocket,clientThread[] t){
this.clientSocket=clientSocket;
this.t=t;
}
 
public String getNama(){
return name;
}
 
@Override
public void run(){
String line;
//String name;
try{
is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
os = new PrintStream(clientSocket.getOutputStream());
os.println("Masukan Nama panggilan Kamu:");
name = is.readLine();
os.println("hai "+ name +" Selamat Datang.ketik logout untuk keluar");
 
for(int i=0; i<=9; i++)
 
if (t[i]!=null && t[i]!=this)
t[i].os.println("*** User "+name+" sudah masuk ke chat room ini !!! ***" );
 
while (true) {
line = is.readLine();
if(line.startsWith("logout")) break;
 
//batas private
if (line.startsWith("+")){
java.util.StringTokenizer ts = new java.util.StringTokenizer(line, ":");
String users = ts.nextToken();
String user = users.substring(1, users.length());
String pesan=ts.nextToken();
for(int i=0; i<=9; i++)
if (t[i]!=null && t[i].getNama().equalsIgnoreCase(user))t[i].os.println(pesan);
//batas private
 
}else{
for(int i=0; i<=9; i++)
if (t[i]!=null) t[i].os.println("<"+name+"> "+line);
}
}
 
for(int i=0; i<=9; i++)
if (t[i]!=null && t[i]!=this)
t[i].os.println("*** User "+name+" meninggalkan chat room !!! ***" );
os.println("*** Bye "+name+" ***");
System.out.println(name+" Offline...");
 
for(int i=0; i<=9; i++)
if (t[i]==this) t[i]=null;
is.close();
os.close();
clientSocket.close();
 
}catch(IOException e)
{};
}
}
Tagged:
Sign In or Register to comment.