socket连接和tcp连接有什么区别?
这两个概念指的是同一件事吗?他们有区别吗?
在我看来,它们是不同的,socket连接是基于tcp连接的。一个套接字包含一个IP地址和端口,它只能连接到另一个套接字,但同一台机器上的一个IP地址和端口可以通过TCP连接与许多其他IP地址和端口连接。这是对的吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
TCP/IP 是用于通信的协议栈,套接字是(双向)通信中的端点。套接字不一定是基于 TCP 的,但这种情况很常见。术语“套接字”也经常用于指操作系统提供的 API,该 API 允许您通过 TCP/IP 堆栈进行连接,例如,Winsock API 提供了用于在 Windows 上通过 TCP/IP 堆栈进行连接的 API 。
套接字唯一地映射到应用程序,因为端口由操作系统为您管理。
进一步阅读:http://en.wikipedia.org/wiki/Internet_socket 和 http://en.wikipedia.org/wiki/Winsock
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
套接字是 会话 中的第 5 层协议.org/wiki/OSI_model" rel="noreferrer">OSI 模型 并且不依赖于底层,这意味着它可以通过 TCP、UDP、MPTCP...(第 4 层 - 传输层协议)。套接字连接用于在节点之间持续交换数据(它在它们之间创建会话),而 TCP 连接则在节点之间可靠地传输数据段。
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.
套接字被定义为通常用于两个进程之间通信的应用程序编程接口(API),但不仅限于此。它们涉及应用程序将链接的库函数、系统调用以及操作系统内核的实现部分。最常见的套接字 API 类型是 Berkely 套接字和 Winsock (Windows)。
根据它们提供的访问类型,套接字的其他分类是:
在Linux、Unix和Windows中,有TCP、UDP和Unix域套接字。上面提到的其他类型的套接字是在Linux中实现的,我不知道它们是否存在于Windows中。
TCP连接是TCP的概念。它连接两个端点,通常是两个进程(或一个进程与其自身),由(IPAddress1、Port1、IPAddress2、Port2)定义。 TCP 连接在 TCP 3 次握手后建立。
在 TCP 中,套接字由两个进程之间的 TCP 连接元素(IPAddress1、Port1、IPAddress2、Port2)定义。
然而,也可以有一个监听套接字。这是一个套接字,允许进程监听其他进程通过网络建立的连接。
https://en.wikipedia.org/wiki/Berkeley_sockets
https://en.wikipedia.org/wiki/Winsock
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:
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
Socket连接意味着两个对等体相互连接,协议可以是TCP或UDP。因此连接不指定连接类型。它是连接的通用术语。
当您说 TCP 连接时,它意味着两个节点使用 TCP 协议连接。
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.