Can TCP IP socket server and client run on same machine?

Answer: Yes, TCP/IP socket server and client applications can be executed on the same machine. TCP Client and server programs are two different and independent application. Just tcp client has to connect to correct address of the tcp server. It doesn’t matter if we are running tcp socket client program on same machine on which tcp server is running or running tcp client from remote machine.

TCP client just need to know the tcp server program address that is IP address and port to which it wants to connect.



As a practice, we mostly use client and server application on same host during client and server application development.

Also, in a project, we may get a feature that requires tcp socket client and server program executing on same machine. If, we don’t want to allow a tcp server to be accessed form remote client, we can use local IP or local host for tcp server.