Hey,
I’m sending messages like “J&0&1&john” to the server and the server sends the message to all the clients. The server receives and send the messages, but the client receives rubbish or nothing after a while. “J 0 1 john” becomes " 0 j hn" or something like that. The server sends the messages to all the sockets with a for loop. I’m using dataoutputstream and datainputstream. What could be the problem?
Sincerely
Here is the code where the server sends messages to the clients:
public void send(String text)
{
System.out.println("** sending: "+text);
for(int i=0;i<oda.getClients().size();i++)
{
Client s=(Client)oda.getClients().elementAt(i);
output=s.getOutput();
try {
output.writeUTF(text);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and the code of the client:
public void run()
{
while(true)
{
try
{
message=input.readUTF();
if(message==null)
return;
else
interpret(message);
System.out.println("** incoming: "+message);
}
catch(SocketException e)
{
stop();
try
{
socket.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
e.printStackTrace();
} catch(IOException e)
{
System.exit(0);
}
}
}