aspose file tools*
The moose likes I/O and Streams and the fly likes Socket - StreamCorruptedException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Socket - StreamCorruptedException" Watch "Socket - StreamCorruptedException" New topic
Author

Socket - StreamCorruptedException

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.
>>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 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 why I got these exceptions and any solution to this problem. What about setting the setting the sender and reaciever buffer size of a socket. please check the code above.
thanks,
Mobeen
Ed Tidwell
Greenhorn

Joined: Oct 22, 2002
Posts: 18
At a quick glance I dont' think you can set the TCP buffers to the values you have given.
That is PART OF THE OS platform that the JVM sits on top of.
So for example I'm willing to bet you can not set the TCP buffer of a wireless card to the same size as the TCP buffer of a 10BaseT connection.
You can ask the JVM how big you want to make your TCP buffers but I'm pretty sure it can ignore this request.
Look at getsendBufferSize() in the Java Docs and notice the key words "buffer size USED BY THE PLATFORM".
You can create you own buffer to pass around and TCP will break it up for streaming over the net behind the scenes. You should look at NIO and Socket Channels.
I hope this was helpful.
Ed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket - StreamCorruptedException