Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good intro to TCP socket programming in Java? [closed]

Tags:

java

sockets

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.

like image 555
Omar Kooheji Avatar asked Jan 26 '09 11:01

Omar Kooheji


People also ask

Should you close a socket Java?

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.

What is close function in socket programming?

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.

What are the TCP sockets available in Java network programming?

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.

Do Java sockets use TCP?

There are two communication protocols that we can use for socket programming: User Datagram Protocol (UDP) and Transfer Control Protocol (TCP).


1 Answers

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.

like image 143
xan Avatar answered Oct 12 '22 12:10

xan