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

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

    s.setTrafficClass(1);
    System.out.println(s.getTrafficClass());

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

    s.setOOBInline(true);
    System.out.println(s.getOOBInline());

    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);/*www  . ja  va  2  s .c o m*/
    int c;
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.shutdownInput();
    s.shutdownOutput();

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

    SocketChannel socketChannel = s.getChannel();
    System.out.println(socketChannel.getLocalAddress());

    s.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ServerSocket ssock = new ServerSocket(Integer.parseInt(args[0]));
    Socket sock = ssock.accept();
    GZIPInputStream zip = new GZIPInputStream(sock.getInputStream());
    while (true) {
        int c;/*from  w  w w .j av a  2 s .  c om*/
        c = zip.read();
        if (c == -1)
            break;
        System.out.print((char) c);
    }
}

From source file:MainClass.java

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

    String hostname = "tock.usno.navy.mil";

    Socket theSocket = new Socket(hostname, 13);
    InputStream timeStream = theSocket.getInputStream();
    StringBuffer time = new StringBuffer();
    int c;/*from  w w  w . j  av  a  2  s  .  c om*/
    while ((c = timeStream.read()) != -1)
        time.append((char) c);
    String timeString = time.toString().trim();
    System.out.println("It is " + timeString + " at " + hostname);
}

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 .ja  v  a 2s. co  m*/
    sock.close();
}

From source file:Time867.java

public static void main(String[] args) {
    String hostname = "tock.usno.navy.mil";
    if (args.length == 1)
        hostname = args[0];//www  .  ja  v a 2  s .c om
    try {
        int c;
        Socket sock = new Socket(hostname, 13);
        InputStream is = sock.getInputStream();
        do {
            c = is.read();
            if (c != -1)
                System.out.print((char) c);
        } while (c != -1);
    } catch (IOException e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Socket t = new Socket("127.0.0.1", 7);
    DataInputStream dis = new DataInputStream(t.getInputStream());
    PrintStream ps = new PrintStream(t.getOutputStream());
    ps.println("Hello");
    String str = dis.readUTF();//w  w w  .  ja v  a  2  s .co m
    if (str.equals("Hello"))
        System.out.println("Alive!");
    else
        System.out.println("Dead");
    t.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int port = 443;
    String hostname = "hostname";
    SocketFactory socketFactory = SSLSocketFactory.getDefault();
    Socket socket = socketFactory.createSocket(hostname, port);

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

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

    in.close();/*from w w  w  .  j a v a 2s  .c  om*/
    out.close();
}