Chat Server
I am attempting to make a multi user chat server with this code. I'm having a problem with sending the message from one user to each other user. I think I'm going in the right direction but I'm getting runtime errors on line 24, NoSuchMethodError. This is most likely due to the attempt of getting the clientArray into the CClient class. If there's an alternative route someone can point me to, I'm open to it. Any other suggestions/comments would be fantastic.
import java.io.IOException;
import java.net.*;
import java.io.*;
import java.util.*;
publicclass ChatServer{
publicstaticint SHCCIS_PORT = 11337;
publicstaticvoid main(String[] args){
int port = SHCCIS_PORT;
ServerSocket serverSocket =null;
Socket sock =null;
CClient[] clientArray =new CClient[20];
try{
serverSocket=new ServerSocket(port);
int i=0;
while(true){
sock = serverSocket.accept();
clientArray[i] =new CClient(sock, clientArray);
i++;
}
}catch(IOException ioe){System.out.println("You screwed up...big time\n"+ioe);}
finally{
try{
serverSocket.close();
}catch(IOException ioe){
System.out.println("something broke\n" +ioe);
}
}
}
}
class CClientimplements Runnable{
private Socket sock;
private BufferedReader in;
private PrintWriter out;
Thread t;
CClient[] clientArray;
public CClient(Socket socket, CClient[] cl){
clientArray = cl;
try{
this.sock = socket;
in =new BufferedReader(new InputStreamReader(socket.getInputStream()));
out =new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
}catch(IOException ioe){System.out.println("You screwed up...big time\n"+ioe);}
t =new Thread(this);
t.start();
}
publicvoid run(){
String message;
try{
while(!(message = in.readLine()).contains("/quit")){
for(int i=0;i<19;i++){
clientArray[i].out.println(message);
clientArray[i].out.flush();
System.out.println(message);
}
}
}catch(IOException ioe){System.out.println("error\n"+ioe);}
finally{
try{
in.close();
out.close();
sock.close();
}catch(IOException ioe){System.out.println("error problem\n"+ioe);
}finally{
}
}
}
}

