Example usage for java.net Socket getInputStream

List of usage examples for java.net Socket getInputStream

Introduction

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

Prototype

public InputStream getInputStream() throws IOException 

Source Link

Document

Returns an input stream for this socket.

Usage

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));
    }/*from   www . j a  v a2s  . co  m*/
}

From source file:SocketDemo.java

public static void main(String args[]) throws Exception {
    String server = args[0];//from ww w . j  a v  a 2s . c  o  m
    int port = Integer.parseInt(args[1]);
    Socket s = new Socket(server, port);

    InputStream is = s.getInputStream();
    DataInputStream dis = new DataInputStream(is);
    System.out.println(dis.readInt());

    s.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    String hostname = "time.nist.gov";
    int port = 37;

    InputStream raw = null;/*from www. ja va2 s  .com*/
    Socket theSocket = new Socket(hostname, port);
    raw = theSocket.getInputStream();

    System.out.println(raw.read());

    raw.close();
}

From source file:SquareServer.java

public static void main(String args[]) throws Exception {
    int port = Integer.parseInt(args[0]);
    ServerSocket ss = new ServerSocket(port);
    while (true) {
        Socket s = ss.accept();
        InputStream is = s.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        double value = dis.readDouble();
        value *= value;/*from  www  . j av  a2s . c  o m*/

        OutputStream os = s.getOutputStream();
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeDouble(value);

        s.close();
    }
}

From source file:Whois.java

License:asdf

public static void main(String args[]) throws Exception {
    int c;//from   w  ww .ja  va2  s  .  c  o  m
    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);
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }
    s.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int port = 443;
    ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
    ServerSocket ssocket = ssocketFactory.createServerSocket(port);

    Socket socket = ssocket.accept();

    InputStream in = socket.getInputStream();
    OutputStream out = socket.getOutputStream();

    // Read from in and write to out...

    in.close();/*from w  w  w  .ja v  a2  s.  c  om*/
    out.close();
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    ServerSocket serverSocket = new ServerSocket(8080);
    Socket socket = serverSocket.accept();

    InputStream inStream = socket.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
    String str = null;//www .j a  va 2 s  .  co m
    while ((str = reader.readLine()) != null) {
        System.out.println(str);
    }
}

From source file:Main.java

License:asdf

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);//ww w  . j ava 2s  .  co  m
    int c;
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.setReceiveBufferSize(1);

    s.close();
}

From source file:Main.java

License:asdf

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);//  ww w.j av a  2 s  .c  om
    int c;
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.sendUrgentData(1);

    s.close();
}

From source file:Main.java

License:asdf

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);//from  ww  w.  j  ava 2  s  .com
    int c;
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    System.out.println(s.toString());

    s.close();
}