I'm looking for a good tutorial on TCP socket programming in Java.
The emphasis is on Good here, often I find that when I lookup this kind of guide I get halfway through before realising that either the person who has written the guide doesn't know what they are talking about or can't express what they know in a way that is condusive to knowledge transfer.
Either that of there are 12 pages of "What are sockets about" and one page of here is some code that uses sockets.
Alternatively if somone wants to write out code snippets for sending text over a TCP socket and waiting for messages on a port that would work too.
The finalize() method is called by the Java virtual machine ( JVM ) before the program exits to give the program a chance to clean up and release resources. Multi-threaded programs should close all Files and Sockets they use before exiting so they do not face resource starvation.
The close function shuts down the socket associated with socket descriptor s, and frees resources allocated to the socket. If s refers to an open TCP connection, the connection is closed. If a stream socket is closed when there is input data queued, the TCP connection is reset rather than being cleanly closed.
Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server. When the connection is made, the server creates a socket object on its end of the communication.
There are two communication protocols that we can use for socket programming: User Datagram Protocol (UDP) and Transfer Control Protocol (TCP).
Does this help at all? http://java.sun.com/docs/books/tutorial/networking/sockets/. It's sun's own sockets tutorial. It has a "what are sockets" part, a "writing to / reading from sockets" section and finally a "read / write pair" simple example as you were asking about.
The waffle:code ratio seems pretty decent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With