Sign in to follow this  

Sockets In Games

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

What is the best way to implement socket sending / receiving in code? Is through polling it in an event loop calling recv / recvfrom along with polling for all your other events or is it with a second thread. Note: I am looking for a cross platform solution. Also which is the better of the following: connection-orientated / connectionless or does that depend on the circumstances of usage, in which case, is the favorable solution: using a connection-orientated socket for main game play, and a connectionless socket for chat commands, etc? In addition, how many sockets does your game use, what are they used for and what information do you deem important to send across the connection? Finally, is it worth using a multicast or broadcast when creating a LAN solution, and how would you go about doing webcast if it is necessary for the internet (please include any information about webcasts - eg. what they are - because I have not actually done any research into what they are, im just curious) Your opinions are appriciated.

Share this post


Link to post
Share on other sites
The Forum FAQ answers most of your questions.

Broadcast on LAN works, if you like that model.

Multicast is a fundamentally broken idea.

"Webcasts" are just a regular web or media server, serving some large number of streams that all take their data from the same source.

Share this post


Link to post
Share on other sites
Yes I did read the forum FAQ afterwards and realised that I'd mostly asked non-questions as far as we're concerned.

Although, I would still like to know what ways there are of receiving data, eg. a second thread or not (primarily)

Share this post


Link to post
Share on other sites
Yes, you can thread if you want, or use select(), or, on Windows, use completion ports or asynchronous select events. All of these are possible, and have different trade-offs.

I find that the best overall solution often is select(). Threading adds a lot of locking cost to most programs (unless each socket is truly independent). select() is portable, reasonable well performing (except in extreme cases), and a very simple model that integrates well with game loops, event loops, or pretty much anything else.

Share this post


Link to post
Share on other sites

This topic is 4689 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.

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