• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket - Stream Corrupted Exception

 
Mobeen Zafar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working on a Chat Server(Client-Applet). Communication between client and server is over sockets. Serialized object has been wriiten and read from the socket ObjectOutputStream and ObjectInputStream.
>>Please check the code below
>>getting server socket
inetAddress = InetAddress.getAllByName(IP);
s = new ServerSocket(Integer.parseInt(serverPort),Integer.parseInt(localPort),inetAddress[0]);
>>server socket accepting client request to connect
Socket C_Soc = s.accept();
C_Soc.setTcpNoDelay(true);
C_Soc.setSoTimeout(20000);
C_Soc.setReceiveBufferSize(100000);
C_Soc.setSendBufferSize(100000);
InputStream in = C_Soc.getInputStream();
i = new ObjectInputStream(in);
OutputStream out =C_Soc.getOutputStream();
o = new ObjectOutputStream(out);
>>code to write on a socket
os.writeObject(SerializedObject);
os.flush();
os.reset();
>>code to read object
Object obj = (Object) in.readObject();
I got StreamCorruptedException on server side if the ObjectOutputStream of a socket is flooded with messages or some times IOException (This someitmes also happens even though the socket is not flooded). This causes My Client Thread which is waiitng to read an Object throws an Exception which results in disconnection of a client from the chat server.
Can somebody reply me as soon as possible why I got these exceptions and any solution to this problem. What about setting the sender and reaciever buffer size of a socket. (pls check the code above).
thanks,
Mobeen Zafar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic