This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket - Stream Corrupted Exception" Watch "Socket - Stream Corrupted Exception" New topic

Socket - Stream Corrupted Exception

Mobeen Zafar

Joined: Nov 05, 2003
Posts: 2
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();
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 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).
Mobeen Zafar
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Socket - Stream Corrupted Exception
Similar Threads
Establishing two-way buffered streams
Serializable problem
How can Socket.getInputStream() block
Socket - StreamCorruptedException
OutputStream.writeUTF( String s )