Sign in to follow this  
Sir Sapo

Simple Game, Complex Networking

Recommended Posts

Sir Sapo    769
I have been trying to get a small simple networking game running for the past 2 days now and I am stuck. I have been using Winsock, but I think its a bit over my head. My question to you guys is, is there anyway to get something networked without going through all the winsock creation and socket binding. All I need to do for this game is to send x and y values back and forth to the server and then to the other client and vice versa.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
There are higher-level socket libraries than WinSock. In .NET and Java, you can get normal output streams to/from sockets. For just plain C++, one that I heard of is http://enet.cubik.org/, but there may be better ones as well.

Share this post


Link to post
Share on other sites
hplus0603    11356
The Forum FAQ is a good place to start; it lists a number of libraries.

However, distributed programming is, in general, hard, and you can't expect to get it all right in just two days of work. Two days isn't much compared to the ten years it takes to become an expert in a field...

Share this post


Link to post
Share on other sites
Sir Sapo    769
I dont plan on being an expert on the subject, but being the only programmer in my indie team puts some pressure on me to know a bit of everything. Anyways, thanks for the help, I'll try some of those libs. The main problem I had with Winsock was that I could get the server to work because it is usually written as a simple console app in tutorials, however the client is the hard part because all the tutorials I have found on Winsock Game Programming have had the client be some fancy DirectX app with lots of stuff in the code not pertaining to networking at all. Anyways, if anyone knows of a place with a sample server and client that just connect to eachother and do nothing else, please let me know.

Share this post


Link to post
Share on other sites
Arelius    196
If you are doing it with UDP then the server and client is almost identical, just one sends the first message, and the other waits

Share this post


Link to post
Share on other sites
hplus0603    11356
Quote from www.gnet.org:

Quote:
GNET is an award-winning environmental technology, news and business center that promotes the use of innovative environmental technologies. This site is made possible by a cooperative agreement from the National Energy Technology Laboratory and the Department of Energy's Office of Science and Technology.


I don't think that's what you actually meant :-)

Share this post


Link to post
Share on other sites
Sir Sapo    769
Thanks for all the replies guys, but I just got Winsock to work and I think I will stick to that. I do have a nother question however. When I send my packet containing playerdata, should I create a struct that hold all the data and then just send one packet that contains the struct, or should I send all the variable seperately in 4 or 5 packets?

I have 8 possible players in a game at one time, so if I send them all the other players information(x position, y position , angle , weapon , name , etc) seperately it comes out to something like 400 packets every tick.

Share this post


Link to post
Share on other sites
hplus0603    11356
You should mash all updates you want to send to a single player at one point in time into a single packet. That way you save on packet overhead. It may serve you well to think of "messages" between game entities, and "packets" (in actual UDP) as a conglomeration of "messages".

Share this post


Link to post
Share on other sites
OrangyTang    1298
Quote:
Original post by hplus0603
You should mash all updates you want to send to a single player at one point in time into a single packet. That way you save on packet overhead.

And make your system more fragile to dropped packets. At some point this starts to become more significant than the packet overhead, so you obviously want to keep your packets between some reasonable min and max sizes.

Share this post


Link to post
Share on other sites
Sir Sapo    769
Quote:

And make your system more fragile to dropped packets. At some point this starts to become more significant than the packet overhead, so you obviously want to keep your packets between some reasonable min and max sizes.


Well, I'm using TCP/IP and I was under the impression that my data is guarenteed to go through if that's what I am using (provided everything else is working).

Share this post


Link to post
Share on other sites
OrangyTang    1298
Quote:
Original post by Sir Sapo
Quote:

And make your system more fragile to dropped packets. At some point this starts to become more significant than the packet overhead, so you obviously want to keep your packets between some reasonable min and max sizes.


Well, I'm using TCP/IP and I was under the impression that my data is guarenteed to go through if that's what I am using (provided everything else is working).

It'll still be guranteed, but that doesn't mean you still don't get affected by dropped packets. Dropped packets will get detected and retransmitted for you, but this takes time. And if a big packet is dropped or corrupted, you will have to retransmit a lot more than if you had smaller packets.

Although IIRC, TCP will try and keep your packets to a suitable size anyhow. But if you're using TCP then you don't have the concept of a packet anywho. [razz]

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