当服务器接受 TCP 连接时端口会改变吗? [英] Does the port change when a server accepts a TCP connection?

查看:29
本文介绍了当服务器接受 TCP 连接时端口会改变吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当客户端使用 TCP 连接到服务器时,会为 TCP 流创建一个新套接字.连接是否保持在建立连接的同一个端口上,还是更改为其他端口?

When a client connects to a server using TCP, a new socket is created for the TCP stream. Does the connection remain on the same port the connection was made or does it get changed to some other port?

推荐答案

新的 socket 是一个应用级的概念,因为每个建立的连接都需要一个唯一的文件描述符(也不同于监听文件描述符),它映射到,但与 TCP 会话不同.会话本身由源地址和目标地址以及端口的组合标识.源(客户端)端口通常是随机选择的,而目标(服务器)端口是监听端口.没有分配额外的端口.

The new socket is an application-level concept introduced because each established connection needs a unique file descriptor (also distinct from the listening file descriptor), which maps to, but isn't the same as, a TCP session. The session itself is identified by the combination of source and destination address and port. The source (client) port is usually chosen at random, while the destination (server) port is the listen port. No additional port is allocated.

这篇关于当服务器接受 TCP 连接时端口会改变吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆