Socket setReceiveBufferSize Example

Started by VelMurugan, Jan 05, 2009, 11:06 PM

Previous topic - Next topic

VelMurugan

Socket setReceiveBufferSize Example

Socket class setReceiveBufferSize example. This example shows you how to use setReceiveBufferSize method.

Socket class setReceiveBufferSize example. ublic void setReceiveBufferSize(int size) throws SocketException Sets the SO_RCVBUF option to the specified value for this Socket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers.

Here is the code

/*
* @ # SetReceiveBufferSize.java
* A class repersenting use to SetReceiveBufferSize method
* of NumberFormat class in java.net package
* version 17 June 2008
* author Rose India
*/

import java.net.*;

public class SetReceiveBufferSize {

    public static void main(String args[]) throws Exception {
        Socket socket = new Socket();

        //Connects this socket to the server.
        socket.connect(new InetSocketAddress("192.168.10.222", 8080));
       
        System.out.println("Buffer Size " + socket.getReceiveBufferSize());
        socket.setReceiveBufferSize(1024);
        System.out.println("Buffer Size " + socket.getReceiveBufferSize());

        socket.close();
    }
}

Output

Buffer Size 43936
Buffer Size 1024

Source : CodingDiary