Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Socket - StreamCorruptedException

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
>>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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Ed
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic