This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
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); >>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
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