Writing to a Socket
by, 04-25-2012 at 10:28 PM (474 Views)
For writing to Java Socket, it is necessary to get the OutputStream. This is done as following:
This is so simple!Java Code:Socket socket = new Socket("jenkov.com", 80); OutputStream out = socket.getOutputStream(); out.write("some data".getBytes()); out.flush(); out.close(); socket.close();
Flush() shall be called when one desires the data which has been sent across web to server. TCP/IP implementation present in OS buffers data & also sends it in big chunks so that it may fit to the TCP/IP packet size.