Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个机器人来模拟一个站点上的不同用户。如果都在同一个端口上,我不知道如何识别哪个虚拟用户应该接收数据包。我想在一个程序上打开多个端口,用谷歌搜索,但我找不到信息。可能吗?
是的,您可以打开多个套接字,每个套接字都侦听不同的端口。
问题是,你需要吗?
如果都在同一个端口上,我不知道如何识别哪个虚拟用户应该接收数据包。
您可以将其构建到协议中,例如消息首先包含用户的标识符(固定字节数),然后是消息的大小(例如:使用 int32_t 存储),然后是实际消息。