This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Sockets and Internet Protocols and the fly likes Socket - Stream Corrupted Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket - Stream Corrupted Exception" Watch "Socket - Stream Corrupted Exception" New topic
Author

Socket - Stream Corrupted Exception

Mobeen Zafar
Greenhorn

Joined: Nov 05, 2003
Posts: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket - Stream Corrupted Exception