Java Socket .setReceiveBufferSize (int size)

Syntax

Socket.setReceiveBufferSize(int size) has the following syntax.

public void setReceiveBufferSize(int size)    throws SocketException

Example

In the following code shows how to use Socket.setReceiveBufferSize(int size) method.


//from  www .  ja  va2 s .c  om

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Main {
  public static void main(String args[]) throws Exception {
    Socket s = new Socket("internic.net", 43);
    InputStream in = s.getInputStream();
    OutputStream out = s.getOutputStream();
    String str = "asdfasdfasdf\n";
    byte buf[] = str.getBytes();
    out.write(buf);
    int c;
    while ((c = in.read()) != -1) {
      System.out.print((char) c);
    }
    
    s.setReceiveBufferSize(1);

    s.close();
  }
}




















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder