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

private Socket(SocketAddress address, SocketAddress localAddr, boolean stream) throws IOException 

Source Link

Usage

From source file:Main.java

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

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

    client.close();/*from  w  w w  .java2 s.c o  m*/
}

From source file:whois.java

public static void main(String[] args) {

    Socket theSocket;// w  ww .ja v  a  2 s  .co m
    DataInputStream theWhoisStream;
    PrintStream ps;

    try {
        theSocket = new Socket(hostname, port, true);
        ps = new PrintStream(theSocket.getOutputStream());
        for (int i = 0; i < args.length; i++)
            ps.print(args[i] + " ");
        ps.print("\r\n");
        theWhoisStream = new DataInputStream(theSocket.getInputStream());
        String s;
        while ((s = theWhoisStream.readLine()) != null) {
            System.out.println(s);
        }
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:finger.java

public static void main(String[] args) {

    String hostname;//from  w  w w. j av  a2s.c o  m
    Socket theSocket;
    DataInputStream theFingerStream;
    PrintStream ps;

    try {
        hostname = args[0];
    } catch (Exception e) {
        hostname = "localhost";
    }

    try {
        theSocket = new Socket(hostname, port, true);
        ps = new PrintStream(theSocket.getOutputStream());
        for (int i = 1; i < args.length; i++)
            ps.print(args[i] + " ");
        ps.print("\r\n");
        theFingerStream = new DataInputStream(theSocket.getInputStream());
        String s;
        while ((s = theFingerStream.readLine()) != null) {
            System.out.println(s);
        }
    } catch (IOException e) {
        System.err.println(e);
    }

}