Reputation: 25
i do not understand how (tcp-)ports work ( in sfml ).
From my understanding a sf::TcpListener
is a sf::TcpSocket
that can not really send or receive data except for accepting connections.
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.
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.
Is there any way i can receive information from a client's implementation in sfml
to which port it was intentionally connecting?
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 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
Is there a better, straight-forward solution i did not think of?
Any help is much appreciated.
Upvotes: 0
Views: 358
Reputation: 409414
You have two different sf::TcpListener
objects. 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.
Upvotes: 1