Jump to content
  • Advertisement
Sign in to follow this  
iam73

Good way of implementing a server in my app?

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

Hi guys,

Beginner in network programming here, trying to add networking to my simple flight sim game to export avionics to a network computer.

I have read on winsock, tried a few things and faced a wall...

I can start my server all right, and can get my client to connect to it and receive data, but my problem is as soon as the server starts listening for incoming connections, the game window freezes and I can't do anything with it, not even close the window, I have to ctrl-alt-del to stop execution. I'm pretty sure I know what's happening (its actually obvious!) I use an infinite loop to listen for incoming connection, then once one come in and is accepted, execution resumes.

What I want to do is keep listening for incoming connections without hanging the rest of the execution.

Creating the server on a different thread seem to be the answer, but before I dive in multi-threading lessons, I wanted some feedback on what is the best way to do what I want to do. I heard about WSAAsyncSelect, which apparently could be another solution.

Can anyone give me some advice?

Thanks guys!

Share this post


Link to post
Share on other sites
Advertisement
Research non-blocking sockets. Threading is a very difficult thing to get right, especially when network communication is involved, and the WSA* functions are basically a nightmare straight from the pit of hell.


Also, moving to the multiplayer/networking forum.

Share this post


Link to post
Share on other sites
For servers, I usually use IOCP. It's a scalable concept that works as it should, and then some. For the client, I'm not sure what would be the best method as I've never done any client networking. ApochiPiQ's suggestion is (I would guess) commonly used for clients, seeing as not many connections are made (except for P2P). (I see my next project coming up :D) Remember, IOCP is mainly for a server with hundreds or thousands of connections, since it solves the horrible "1 client per thread" drama.

http://www.codeproject.com/KB/IP/iocp_server_client.aspx
http://msdn.microsoft.com/en-us/magazine/cc302334.aspx
http://www.codeproject.com/KB/IP/iocp.aspx

Share this post


Link to post
Share on other sites

How do you think servers are implemented on OSes that don't have IOCP, i.e. everything not-Windows? ;-)


Non-blocking sockets my guess (I'm not a Unix/iOS person), but I assumed he was aiming for Windows since:

I heard about WSAAsyncSelect, which apparently could be another solution.
[/Quote]

:]

Share this post


Link to post
Share on other sites

[quote name='ApochPiQ' timestamp='1323919708' post='4894062']
How do you think servers are implemented on OSes that don't have IOCP, i.e. everything not-Windows? ;-)


Non-blocking sockets my guess (I'm not a Unix/iOS person), but I assumed he was aiming for Windows since:

I heard about WSAAsyncSelect, which apparently could be another solution.
[/Quote]

:]
[/quote]



On servers from the dinosaur ages, you would poll the accepting socket, and every other socket, each time through your main loop, using select(). If select() shows the accepting socket as readable, then it is possible to call accept() at least once on that socket without blocking.

On modern servers, you use some kind of notify-based I/O -- epoll, for example, on Linux. In the UNIX world, libevent is used to mitigate the differences between Solaris, BSD, Linux, etc.

If you want a library that can do non-blocking networking in a scalable fashion across many operating systems, including Windows, then boost::asio is probably a good fit.

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!