Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any difference between socket connection and tcp connection?

Tags:

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?

like image 835
Thomson Avatar asked Jun 21 '11 02:06

Thomson


People also ask

Is TCP based on socket?

TCP socket is a connection-oriented socket that uses the Transmission Control Protocol (TCP). It requires three packets to set up a connection: the SYN packet, the SYN-ACK packet, and the ACK packet. TCP socket is defined by the IP address of the machine and the port it uses.

How many sockets are in a TCP connection?

For most socket interfaces, the maximum number of sockets allowed per each connection between an application and the TCP/IP sockets interface is 65535.

What is a socket connection?

A socket is a communications connection point (endpoint) that you can name and address in a network. Socket programming shows how to use socket APIs to establish communication links between remote and local processes.

Is socket TCP or UDP?

Socket TypesStream sockets use TCP (Transmission Control Protocol), which may be a reliable, stream oriented protocol, and datagram sockets use UDP (Unix Datagram Protocol), which is unreliable and message oriented.


2 Answers

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

like image 159
Matt Esch Avatar answered Sep 17 '22 07:09

Matt Esch


Socket is layer 5 protocol (Session) in OSI Model and is not dependent on underlying layers which means it can be over TCP, UDP, MPTCP, ... (Layer 4 - Transport layer protocols). Socket connection is used for continues exchange of data between nodes (it creates a session between them) but TCP connection makes a reliable transmission of data segments between nodes.

like image 35
Keivan Avatar answered Sep 17 '22 07:09

Keivan