我正在关注一个关于java中套接字编程的材料,我遇到了问题。我的服务器对象没有 .sendToAll() 方法和 .removeConnection() 方法。请有人指出我正确的方向。下面是代码。
public class ServerThread extends Thread {
Server server;
Socket socket;
public ServerThread(Server server, Socket socket){
this.server = server;
this.socket = socket;
//start the thread
start();
}
public void run(){
try{
DataInputStream din = new DataInputStream(socket.getInputStream());
while (true){
String message = din.readUTF();
System.out.println("Sendong "+ message);
server.sendToAll(message);
}
}catch(EOFException x){
}catch (IOException x){
x.printStackTrace();
}finally{
server.removeConnection(socket);
}
}