Example usage for java.net Socket Socket

List of usage examples for java.net Socket Socket

Introduction

In this page you can find the example usage for java.net Socket Socket.

Prototype

public Socket(InetAddress address, int port) throws IOException 

Source Link

Document

Creates a stream socket and connects it to the specified port number at the specified IP address.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);

    System.out.println(client.isInputShutdown());

    client.close();/*from w  w  w  .ja  v  a 2  s  .  c  o m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);

    System.out.println(client.isOutputShutdown());

    client.close();/*w  ww  .ja  va 2s.c o m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);

    System.out.println(client.getKeepAlive());

    client.close();/*w ww  .  j  a v  a2 s.  c o m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);
    client.setSendBufferSize(1000);//from  w  w  w  .  j  a va 2s. c o  m
    System.out.println(client.getSendBufferSize());

    client.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);

    System.out.println(client.getLocalAddress());

    client.close();//from  w  w w. ja  v a 2 s. c o m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);

    System.out.println(client.isConnected());

    client.close();//from  w  w w.jav  a2 s.  com
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);

    System.out.println(client.getLocalPort());

    client.close();//www . ja v a 2  s.  c o  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);

    System.out.println("Just connected to " + client.getRemoteSocketAddress());

    client.close();/*from  w w w.j ava  2 s. c o m*/
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Socket s = new Socket(args[0], 13);
    InputStream is = s.getInputStream();
    while (true) {
        byte b[] = new byte[100];
        int i = is.read(b);
        if (i == -1)
            break;
        System.out.print(new String(b, 0, i));
    }/*w  w w . ja v a 2  s. c o m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket sock = new Socket(args[0], 1234);
    DataInputStream dis = new DataInputStream(sock.getInputStream());
    float f = dis.readFloat();
    System.out.println("PI=" + f);
    dis.close();//from  w w  w  .j a  v a2s .c  o m
    sock.close();
}