Building Java Client/Server Applications with TCP. Part 2
1 min readFeb 27, 2020
The second article in our series on Building Java Client/Server Applications with TCP.
2. Sockets programming in Java
A network socket is an internal endpoint for sending or receiving data within a node on a computer network.
When a Java program would like to establish a TCP connection between two computers with sockets, the following steps need to be covered:
- The server instantiates the ServerSocket class with the port number.
- The server invokes the accept() method of the ServerSocket class and waits until a client connects to the server on the given port.
- The client instantiates the Socket class, attempting to connect to the specified server and the port number.
- On the server side, the accept() method returns a reference to a new socket, to be connected to the client socket.
- On the server side, the accept() method returns a reference to a new socket, to be connected to the client socket.
The ServerSocket class can be instantiated through the constructors presented in the table below:
Find out more at — http://bit.ly/387Sn1n
Originally published at https://www.luxoft-training.com.