Jump to content
  • Advertisement
Sign in to follow this  
Artum

SDL_Net Noob General Questions

This topic is 4188 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

Howdy all, I've got a couple of questions if anyone has some time to answer them: Info about me, skip if you don't care. :-P I've been writing poor code in C++ for about 4.5 years now and in the last year or so I've started a few small 2D Zelda-like games that I never fully finished. I've also been using SDL for almost a year now and I'd like to try my hand at making a network game. Don't worry, I'm not (completely) crazy- no MMOs for me. Just something small and mostly simple- 4 players (probably 2 to start out with), 2D, action RPG similar to Zelda on the SNES. A couple different classes, maybe a level cap of 5, and 4 or so abilities, plus melee, per class. Figured I'd start with one town, one dungeon to explore, and go from there if I got that working. I've never done any network programming before so I don't really know where to start. Now on to the questions: 1) Does anyone know if SDL_Net would be a good place to start my network fun? 2) Assuming the rest of my game works and works well, would SDL_Net suffice for my needs? 3) And, does anyone know of any helpful tutorials for SDL_Net that they'd recommend? I'm reading over the documentaion for SDL_Net right now, but that's as far as I've gotten. Thanks for taking the time to help out, I need all the help with this I can get. -Artum. Edit: Oh, and I don't plan on learning how to use SDL_Net by diving into a game. I'll of course write a couple of smaller, simpler programs to learn. Then apply my knowledge to whatever game I end up creating.

Share this post


Link to post
Share on other sites
Advertisement
First I would look at some simple client server programs. The most popular for a first example is usually a simple chat server that allows a connection to be made, sends a message and closes the connection. Then it moves on to allow the client to connect, type some stuff and the server sends it back. Then it moves on to process the information the client typed and send it to other connected clients. Moving on from there you introduce some processing logic to manipulate what the clients send to give custom information to the other clients based on settings.

This stage is the generic client server architecture we all know and love however the concept may seem simple but there is a lot of planning that goes into a multiplayer game. From my experience (limited) you will want to keep 3 things in mind (of course this is general and there are way more than 3):
1. Never trust client input. All clients are cheaters. Don't trust anything you don't absolutely have to.
2. Keep the network traffic to a minimal (I know... duh...). Send periodic updates to keep people in sync with the game but figure out what is necessary and what isn't to keep the game smooth. Try not to re-send information to the client who initially sent the information to the server. Any network traffic that isn't necessary is a potential bottleneck.
3. Design in the beginning will save you a ton of headaches later. Especially when working with networking (and even more so when working with threading). Give some serious thought to how the game will flow. UML is especially helpful in this regard. Here is a link to a tutorial on some common UML diagrams and here is a link to some UML software that has a community version that is aimed more towards learning UML but can be helpful if you have never used it before. I have used it a few times but I have been forced to use Visio at work so I use that mostly now.

[edit] - I forgot I did a simple chat server not too long ago. May be helpful. Let me know if it is.
Download here

Share this post


Link to post
Share on other sites
You might want to try Net2 rather than SDL_Net. Read the page for some reasoning behind this.

As for SDL_Net itself, it's a thin layer over platform-dependent networking. It is perfectly adequate but it's quite low-level.

Personally I write my own low-level network code, but I appreciate that isn't for everybody, though it's really not that hard compared to rendering, physics, sound, etc.

Share this post


Link to post
Share on other sites
SDL net is low-level, but it would probably be a good idea to write some simple network code first. You don't need to create a full blown network engine, a program that sends character positions over a network would be good. Once you have an idea of what you need, you can either use a higher level engine, or add more features to SDL net.

Share this post


Link to post
Share on other sites
Awesome, thanks a bunch guys. Looks like I'll be looking into Net2 as well. And thanks for the UML link, I'm definitely going to be using that.

Thanks again,
-Artum.

Share this post


Link to post
Share on other sites
evillive2:
I can't make your chat program work...
i dont understand what is main.cpp for and what is chat_server.exe really for..
It would be of great help if I can make this work and learn from this program.


Can anyone help me? :D
I'm trying to create a turn-based board game like chess. as far as i can think, it will only require to send/receive strings/data w/c contains information on the new move(w/c piece and where) which the other player made.

which one will be easier to implement TCP or UDP? Do you think it will be ok to use UDP in this kind of game?

Thanks!

Share this post


Link to post
Share on other sites
bluehunter, a private message might have been a better idea here.

You should be almost certainly using TCP for a turn-based game anyway. UDP is better for when you send many status updates and it doesn't matter that you miss the occasional one.

Share this post


Link to post
Share on other sites
Sorry, I will send a PM too in case a mod wants to move these posts...
Quote:
evillive2:
I can't make your chat program work...
i dont understand what is main.cpp for and what is chat_server.exe really for..
It would be of great help if I can make this work and learn from this program.


main.cpp is the actual code used to generate chat_server.exe. It has a few flaws in it that I should probably fix but you can use something like telnet to connect to it from multiple computers or multiple times from the same computer.

Any specific questions feel free to PM me.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!