SFML community forums
Help => Network => Topic started by: D on December 15, 2010, 01:48:16 am
-
Hi. I'm starting out with SFML and the networking side of it. My question is following: Am I able to resolve the local port that is used by sf::SocketUDP? I took a look at the SFML2.0 api, which has this (http://www.sfml-dev.org/documentation/2.0/classsf_1_1UdpSocket.htm#afacddd4a2d3ecb54e503f30850cdd64f) method, which will eventually return the port I'm after. But is there a way to do that in 1.6?
I'm a complete beginner what comes to networking, so I'll explain a little more why I think I need that port.
Server binds a port (in my test case 51337). When client sends something to that port, it sends it via another free port, which is assigned to it by operating system. Right? So if server returns something to client after getting the packet from client, it replies it to the port that the data came from. But if the client wants to receive that data that server just sent, it needs to bind the socket it's using. And because I cant resolve the local port, I'll need to manually bind some port, which causes problems if I run another client and it uses the same port.
Does my thinking make any sense, or am I completely lost? :D Thanks for advance.
(I'm using SFML 1.6, C++ and Mac OS X 10.6)
-
You can't get this port in SFML 1.6.
But to solve your problem, you can try to bind your socket to port 0, I think the OS will give you a free port (not sure about that, though).
-
Thanks for the answer. I tried binding it to 0, with no luck. Strange, I thought this was kind of a basic functionality, but I'll test the 2.0 out then.