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 Server)

edited April 2013 in Share
SERVER

package serverconsul;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
/**
*
* @author ridwansyah
*/
public class Server {
static Socket clientSocket = null;
static ServerSocket serverSocket = null;
static clientThread t[] = new clientThread[10];
 
public static void main(String args[]) {
 
BufferedReader br = null;
PrintStream ps = null;
String line,nama;
int port_number=6666;
 
if(args.length < 1){
System.out.println("Port number="+port_number);
}else{
port_number=Integer.valueOf(args[0]).intValue();
}
 
try {
serverSocket = new ServerSocket(port_number);
}catch (IOException e){
System.out.println(e);
}
 
while(true)
{
try {
clientSocket = serverSocket.accept();
for(int i=0; i<=9; i++){
if(t[i]==null){
br=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
ps = new PrintStream(clientSocket.getOutputStream());
ps.println("Masukan Nama Lengkap Kamu :");
nama = br.readLine();
(t[i] = new clientThread(clientSocket,t)).start();
// System.out.println(t[i].getName());
System.out.println(nama+" Online...");
break;
}
}
}
catch(IOException e){
System.out.println(e);
}
}
}
}
Sign In or Register to comment.