Any difference between socket connection and tcp connection?

后端 未结 4 1680
南方客
南方客 2021-01-31 10:59

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 cont

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 11:46

    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

提交回复
热议问题