Java networking Examples: Client and server implementation in TCP
TCP (Transmission Control Protocol) is a transport layer protocol which deals with end to end transmission. It makes a reliable connection. Let us create a client server program using TCP. Program implementation: Server: The implementation starts with including the built in packages. The steps are given below. A public class is created with main() function. A ServerSocket object is created with the port 12345. Clientsocket object is derived from Socket. The object calls the accept() function to accept the clientsocket. ‘getInetAddress()’ is used to get the internet Address. ‘getOutputStream()’ is used to get the output stream from the socket. ‘PrintWriter’ object writer1 gets the outputStream as a input. Print the output as response from server. Close() the socket. Server Program: import java.net.*; import java.io.*; public class TCPServerEg { public static void main(String[] args) { ...