Hello,
I am (still) writing a server+client application.
I start the server. After a connection is accept()-ed, I start a thread to handle that connection.
On the handler thread, I add the client nickname(String) and Socket to a Hashtable.
private Hashtable<String, Socket> clients = new Hashtable<String, Socket>();
clients.put(nickname, socket);
After a client connects, he can send messages to other clients. This is done by this function:
public void forwardMessage(String destination, String message){
System.out.print("forward(destination, message): ");
if (serverMain.nameToSocket(destination)!=null){
try {
Socket socketDestination = serverMain.getHashClients().get(destination);
System.out.println("name/socket destination= "+destination+ " " +serverMain.getHashClients().get(destination));
ObjectOutputStream oos = new ObjectOutputStream(socketDestination.getOutputStream());
oos.writeObject(message);
//return true;
} catch (IOException e) {e.printStackTrace();}
}
//return false;
}
However, on the client side, receiving fails
java.io.StreamCorruptedException: invalid type code: AC
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at defaultPackage.ClientHandler.run(ClientHandler.java:44)
at java.lang.Thread.run(Unknown Source)
at this line:
message = (String) ois.readObject();
What am I doing wrong?