I'll just cut to the chase here.I want to send a message from the server to all the clients.My approach is to make an array list of all the clients that are currently coected the server.If anyone user sends a message,I simply iterate through the list and send each of the clients a message.The problem is that my clients are not receiving any message.Here is my send method on server-side.
private void message() {
while(true)
{
DataInputStream fromClient;
try {
fromClient = new DataInputStream(socketNew.getInputStream());
message=fromClient.readUTF();
for(Socket s:socs)
{System.out.println(message);
DataOutputStream toClient=newDataOutputStream(s.getOutputStream());
toClient.writeUTF(message);
}
message="";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Here is my receive method on client side:
private void receive_data()
{
{
DataInputStream fromServer;
try {
fromServer = new DataInputStream(socket.getInputStream());
message=fromServer.readUTF();
console(message);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Any suggestions on where I might be doing it all wrong?Thanks for your time.
