Any difference between socket connection and tcp connection?

24,551

Solution 1

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

Solution 2

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.

Solution 3

Sockets are defined as an application programming interface (API) for communication usually between two processes, but not limited only to this. They involve library functions your application will link with, system calls, and implementation part of the operating system kernel. The most common types of socket APIs are Berkely socket and Winsock (Windows).

Other classification of socket for the type of access they provide is:

  • TCP sockets: to establish TCP connections
  • UDP sockets: for UDP communication
  • Packet sockets: for direct access to layer 2
  • Unix domain sockets: for IPC through files within the same node
  • Raw socket for direct access to IP layer
  • Routing sockets
  • SCTP sockets
  • Other types of sockets

In Linux, Unix, and Windows, there are TCP, UDP, and Unix domain sockets. The other types of sockets mentioned above are implemented in Linux and I don't know if they exist in Windows.

TCP connection is a TCP concept. It connects two endpoints, usually two processes (or one process to itself) and it's defined by (IPAddress1, Port1, IPAddress2, Port2). The TCP connection is established after TCP 3-way handshake.

In TCP a socket is defined by the elements of a TCP connection between two processes (IPAddress1, Port1, IPAddress2, Port2). However, there can be also a listening socket. This is a socket that a allows a process to listen for connections established from other processes through the network.

https://en.wikipedia.org/wiki/Berkeley_sockets

https://en.wikipedia.org/wiki/Winsock

Solution 4

Socket connection implies two peer connected with each other,Protocol can be TCP or UDP.So connection does not specify type of connection.it is generic term for connection.

When you say TCP connection it implies two nodes are connected using TCP protocol.

Share:
24,551

Related videos on Youtube

Thomson
Author by

Thomson

Human debugger.

Updated on July 09, 2022

Comments

  • Thomson
    Thomson almost 2 years

    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?

  • Thomson
    Thomson about 13 years
    Thanks for the clarification. So how about the socket connection based on TCP? What's the difference between TCP based socket connection and TCP connection?
  • theking2
    theking2 over 2 years
    Perhaps as addon: Internet sockets (TCP. UDP etc.) are identified by a host address and a 16-bit port number (0- 65535) a Unix domain socket or a inter-process (on the same node) communication socket is identified by a file name.