简体   繁体   English

sfml中已连接客户端的端口

[英]port of connected client in sfml

i do not understand how (tcp-)ports work ( in sfml ). 我不了解(tcp-)端口的工作方式(在sfml中)。

From my understanding a sf::TcpListener is a sf::TcpSocket that can not really send or receive data except for accepting connections. 根据我的理解, sf::TcpListener是一个sf::TcpSocket ,除了接受连接之外,它实际上无法发送或接收数据。

Let's assume i have multiple listeners on different ports: think of them like clients for my game (first port) and a config-tool (second port) which i'm writing right now. 假设我在不同的端口上有多个侦听器:将它们像我游戏中的客户端(第一个端口)和我现在正在编写的配置工具(第二个端口)一样。

I'd like to handle sf::Packet s differently depending on which port i received them. 我想以不同的方式处理sf::Packet具体取决于我接收它们的端口。

But here is the problem: I don't know how the connect works, but i guess it must assign a different port ( otherwise i would have two clients both running on localhost connected to the same port). 但这是问题所在:我不知道连接的工作方式,但是我想它必须分配一个不同的端口(否则我将有两个都在本地主机上运行的客户端连接到同一端口)。 so i cannot switch on the port anymore. 所以我不能再switch端口了。

  • Is there any way i can receive information from a client's implementation in sfml to which port it was intentionally connecting? 我有什么办法可以从sfml的客户端实现中接收信息,将其有意连接到哪个端口?

  • Is there a algorithm which i can use to determine which port it was (the current port is close to the intentional port or something like this)? 我是否可以使用一种算法来确定它是哪个端口(当前端口靠近故意端口或类似端口)?

  • Do i need to store this in a struct like 我是否需要将其存储在类似的struct

    struct wrapped_socket { uint16_t intentional_port; sf::TcpSocket socket; };

    which would reqire to change my current server-codebase ( call to wrapped_socket::socket->send() instead of socket->send , or 这将需要更改我当前的服务器代码库(调用wrapped_socket::socket->send()而不是wrapped_socket::socket->send() socket->send ,或者

  • Is there a better, straight-forward solution i did not think of? 我没有想到更好,直接的解决方案吗?

Any help is much appreciated. 任何帮助深表感谢。

You have two different sf::TcpListener objects. 您有两个不同的sf::TcpListener对象。 You check for connections on the first listener object, and put those connections in one collection. 您检查第一个侦听器对象上的连接,并将这些连接放在一个集合中。 Then you check for connections on the second listener object, and put those connections in a second collection. 然后,检查第二个侦听器对象上的连接,并将这些连接放在第二个集合中。

That way the connections are separate, and can therefore be handled accordingly. 这样,连接是分开的,因此可以相应地进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM