Sign in to follow this  
danieliskogen

Bidirectional SDL_net TCP

Recommended Posts

Hi everyone! This is my first post here. I'm currently making small game/project which atm is just two sprites in a tile map. One sprite is controlled by the local player, and the other by a remote player. So the idea basically is: - Send local player's coordinates - Receive remote player's coordinates Pretty much your run of the mill newbie first attempt network game =) Atm, client sending data to server works fine, but as soon as I try to send something back, the game freezes. I guess it's because both server and client is stuck waiting for data with SDLNet_TCP_Recv(). What are my options here? Someone game me a tip having a thread receiveing data, so I tried a bit with SDL threads, but I had problems since SDL threads (threads in general?) and classes don't go well togehter. All my networking methods are in a class, so I need the thread to be a class member. Are there any other ways to get around this, or is the thread idea the only one? Thank you in advance. - Daniel

Share this post


Link to post
Share on other sites
The basic game loops for a networked game look like in http://www.mindcontrol.org/~hplus/networked-game.html.

The most important part to understand is how to use select() to guarantee that your send() and recv() calls don't block. You never want to use a blocking call within the main game loop.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this