View RSS Feed

Java Socket

Socket programming and networking examples in Java.

  1. Reading from a Socket

    by , 04-25-2012 at 11:29 PM
    Obtain InputStream for reading from Java Socket. This is done as following:
    Java Code:
    Socket socket = new Socket("", 80);
    InputStream in = socket.getInputStream();
    int data =;
    //... read more data...
    Pretty simple, right?

    This shall be noticed that one canít read always from the InputStream of Socket till -1 is returned, as it could be done while a file ...