Advertisement

SDLNet: Talking to myself

Started by February 04, 2017 11:03 PM
0 comments, last by frob 7 years, 9 months ago

Hi,

I'm developing a game that is intended to be online, but at the moment I only have a single box. I thought it would be a good idea to put the eventual player movements in now as a pseudo-network (essentially, P2P). I don't know a lot about networking, though.

I'm using SDNet (based off of this http://www.sdltutorials.com/sdl-net-part-1-user-tutorial), and running into a problem where I can't get a socket to receive messages. I have the basic setup working using localhost (127.0.0.1).

Do I use two separate sockets? One for send and one for receive? If so, do I send and receive on the same port?

It can work, but the underlying connection architecture needs to be carefully thought out.

You can connect two machines with one socket. You can have multiple games on the single machine attaching to each other if you design it as a star, with one game acting as the central hub and the others acting as a star. It isn't what many people consider P2P, but it generally works out well enough.

Brief networking tutorial on how it works:

An IP header has four values. { Source IP, Source Port, Dest IP, Dest Port }

When a server starts listening for a connection you establish server's IP and the server's port. In your case your source IP is the loopback, and the port is whatever you assign. The server is looking for { Any IP, Any Port, loopback, port_number_you_specify }

When a client attempts to connect you establish two more. The source IP is from the client. Normally (unless you specify a port)the operating system decides the port to be any unused value. So when connecting it will look like this: { loopback, automatically_generated_unused_port, loopback, port_number_you_specify } Since automatically_generated_unused_port is different for every game client they should all be able to connect over a unique connection.

The example looks like it should work directly out of the box, so it could easily be something else. Assuming Windows, make sure the port is open in Windows Firewall or another antivirus/antispam/proxy program blocking the connection.

This topic is closed to new replies.

Advertisement