File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
I agree. Here's the link:
subject: Socket - Stream Corrupted Exception
It's not a secret anymore!