Tolong pilih kategori sesuai, jenis posting (pertanyaan atau bukan) dan sertakan tag/topik yang sesuai misal komputer, php, mysql, dll.
Promosi atau posting tidak pada tempatnya akan kami hapus.
Mencantumkan kode program di posting Anda, tolong ikuti aturan yang sesuai, baca http://diskusiweb.com/discussion/39204/aturan-cara-menyisipkan-kode-program-di-diskusiweb

Baca cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Chatting Java Room + Private (Class Client)

edited April 2013 in Share
CLIENT


package clientconsul;
 
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
/**
*
* @author ridwansyah
*/
public class Client implements Runnable {
 
static Socket clientSocket = null;
static PrintStream os = null;
static BufferedReader is = null;
static BufferedReader inputLine = null;
static boolean closed = false;
 
public static void main(String[] args) {
 
int port_number=6666;
String host="localhost";
 
if (args.length < 2)
{
System.out.println("Host = "+host+", port_number = "+port_number);
} else {
host=args[0];
port_number=Integer.valueOf(args[1]).intValue();
}
 
try {
clientSocket = new Socket(host, port_number);
inputLine = new BufferedReader(new InputStreamReader(System.in));
os = new PrintStream(clientSocket.getOutputStream());
is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
 
} catch (UnknownHostException e){
System.err.println("Host tidak ditemukan "+host);
} catch (IOException e) {
System.err.println("Tidak dapat menampilkan I/O "+host);
}
 
if (clientSocket != null && os != null && is != null){
 
try {
new Thread(new Client()).start();
while (!closed){
os.println(inputLine.readLine()+'\n');
}
os.close();
is.close();
clientSocket.close();
 
}catch (IOException e) {
System.err.println("IOException: " + e);
}
}
}
 
@Override
public void run(){
String responseLine;
try{
while ((responseLine = is.readLine()) != null) {
System.out.println(responseLine);
if (responseLine.indexOf("*** Bye") != -1) break;
}
closed=true;
} catch (IOException e){
System.err.println("IOException: " + e);
}
}
}




Smoga dapat membantu :D
Sign In or Register to comment.