Saturday, January 19, 2013

Network talk

Hey again guys!

So with all the sprites done I figured I'd put a spritesheet on the blog. If you want to see it, it's on the concept art page of the blog. I'm very pleased to be done with this, so I can finally start working on the network code.
It shouldn't be too hard to get it all to work, as our game's mechanics force synchronous behaviour. I did ran into a few problems earlier tho. I've created a server which keeps track of all the games, and sends them to the game when you search for games. The server itself is already done by now. The problem I ran into was the fact I wanted to use the IPAddress of the host as the key for a dictionary (which represents the gamelist).
I tried to send the IP of the host to the server, so I needed the external IP of the computer on which the game was running. The only way to do that is to get your IP from a service like whatsmyip.org, but they all have rules similar to things like, only 1 lookup per 5 minutes. But even for our testing purposes we might overdo that. So I kept thinking and came up with the idea of not sending the IP, but just getting the IP on the server end, which is way easier.


Socket s = client.Client;
IPEndPoint tempip = s.RemoteEndPoint as IPEndPoint;
return tempip.Address;

You'd put this in a method and pass it the client you're connected to. So in our code, as soon as a connection starts the method is called and we get our IP address which we can then use as a key in our dictionary, if the user decides to create a new game.
On the server console that would look like this:

I don't know who added the lovely little rabbit, but I like it.

That's it for today folks, see you around next time.

Ruben

No comments:

Post a Comment