Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket - StreamCorruptedException  RSS feed

Mobeen Zafar
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
InputStream in = C_Soc.getInputStream();
i = new ObjectInputStream(in);
OutputStream out =C_Soc.getOutputStream();
o = new ObjectOutputStream(out);
>>code to write on a socket
>>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.
Ed Tidwell
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!