View RSS Feed

Java Socket

Socket programming and networking examples in Java.

  1. Writing to a Socket

    by , 04-25-2012 at 11:28 PM
    For writing to Java Socket, it is necessary to get the OutputStream. This is done as following:

    Java Code:
    Socket socket = new Socket("jenkov.com", 80);
    OutputStream out = socket.getOutputStream();
    
    out.write("some data".getBytes());
    out.flush();
    out.close();
    
    socket.close();
    This is so simple!

    Flush() shall be called when one desires the data which has been sent across web to server. TCP/IP ...
    Categories
    Tutorial