question

aboulianne avatar image
aboulianne asked

Binding socket in custom server

Hello,

I'm close to having a successful implementation of a custom game server hosted and launched by PlayFab, but I still need a clarification to make sure everything is done correctly and in a secure manner.

On the server, when binding the socket to an address and port,

(c# tcp: new TcpListener(address, port) c# udp : socket.bind(new IPEndPoint(address, port) ); )

what address do I specify in the address parameter?

I noticed the server is launched with a -server_host_domain= parameter, which I believe provides the public IP address, but I believe this isn't what I am meant to use. (Also probably why I had issues on another topic I posted a few weeks ago.)

I tried using IPAddress.Any (0.0.0.0). This works, but I wonder if it's the good thing to do, or if it isn't secure and opens my server code to unwanted communications.

In my title, the latest (successful) test is the "micro" build.

If needed, I can provide the source code to it, which is just 120 lines that parse command line args and opens a socket in TCP or UDP, outputing several traces in the process.

Thanks for your help!

(p.s. this is related to my previous post :

https://community.playfab.com/questions/15784/socket-bind-failed-already-in-use-unity-hlapi-cust.html )

Custom Game Servers
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Yes, the server_host_domain passed in is the IP Address of the server host, and the server host can only have one IP Address, so Any would be fine, as long as you're specifying the correct port, but it's also worth tracking down why the real IP Address wasn't working for you. What logging information do you get for those calls? Also, you do mean you're using one or the other, depending on some internal logic, right? Not both?

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

aboulianne avatar image aboulianne commented ·

Hello Brendan,

when calling socket.Bind using the specified IP address (as provided by -server_host_domain), I get the following exception in C#:

Exception: System.Net.Sockets.SocketException (0x80004005): The requested address is not valid in its context
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at microserver.Program.TryStartServer()

Using the same code, if I change the command line so the server_host_domain is forced to 0.0.0.0 (equivalent to IPAddress.Any), then no exception occurs and the code proceeds as expected.

I'll attach the test server I have. It's made so that it accepts command line arguments as provided by playfab, and can accept -use_tcp=true or =false to try either UDP or TCP (default). All it does is open a port for listening, then sleeps forever (so it must be killed after use, there is no exit point.)

microserver.zip

0 Likes 0 ·
microserver.zip (1.1 KiB)
brendan avatar image brendan aboulianne commented ·

There's nothing wrong with using IPAddress.Any - you can just use that. The error you're seeing is saying that there's something wrong with the IP Address you're specifying - if you want to specifically solve that, can you log the details of the actual values you're passing in and paste that here?

0 Likes 0 ·
aboulianne avatar image aboulianne brendan commented ·

Sure, here's the output from the last test where I got an error:

Assigned ip address 54.243.25.70 port 9000

(so this is the content of <server_host_domain> and <server_host_port>)

This matches what I see in the last two Archived Games on my title.

(Lobby 13578DC4C92E5BD9 for instance)

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.