Any difference between socket connection and tcp connection?

Thomson picture Thomson · Jun 21, 2011 · Viewed 19.4k times · Source

Are these 2 concepts refer to the same thing? Do they have difference?

In my opinion, they are different, and socket connection is based on tcp connection. A socket contains an IP address and port and it could only connect to another socket, but an IP address and port in the same machine could be connected with many other IP addresses and ports with TCP connection. Is this right?

Answer

Matt Esch picture Matt Esch · Jun 21, 2011

TCP/IP is a protocol stack for communication, a socket is an endpoint in a (bidirectional) communication. A socket need not be TCP based, but it is quite often the case. The term socket is also often used to refer to the API provided by the operating system that allows you to make a connection over the TCP/IP stack, for example, the Winsock API provides an API for connections over the TCP/IP stack on Windows.

A socket is mapped uniquely to an application as the ports are managed for you by the operating system.

Further reading: http://en.wikipedia.org/wiki/Internet_socket and http://en.wikipedia.org/wiki/Winsock