Jump to content
  • Advertisement
Sign in to follow this  

SDLNet: Talking to myself

This topic is 678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



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 (


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

Edited by Steno

Share this post

Link to post
Share on other sites

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, loopbackport_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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!