View RSS Feed

Java Socket

Writing to a Socket

Rate this Entry
by , 04-25-2012 at 11:28 PM (556 Views)
For writing to Java Socket, it is necessary to get the OutputStream. This is done as following:

Java Code:
Socket socket = new Socket("", 80);
OutputStream out = socket.getOutputStream();

out.write("some data".getBytes());

This is so simple!

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.

Submit "Writing to a Socket" to Facebook Submit "Writing to a Socket" to Digg Submit "Writing to a Socket" to Submit "Writing to a Socket" to StumbleUpon Submit "Writing to a Socket" to Google