Archived

This topic is now archived and is closed to further replies.

neonfaktory

New to Network Programming - Help Please?

Recommended Posts

Ok, here''s my situation. I''ve been making a game in C++ (VC++ 6.0), like many, and now think its an appropriate time to implement my Networking Framework, as to build it WITH my engine for a smooth integration (hopefully). I would like to implement a Client/Server setup, with a simple Lobby to "collect" a pool of playing connections with the possibility of mid-game joining, but only if it isnt a chore to implement. I know many of you are programming wizzes that know all about advanced networking shat and could probably bang out what I need in no time... So I come to you for a shove in the right direction and possibly make my venture into network programming THAT much easier by spending a few mins to reply . First, what should I invest my time/research into in order to get networking into my game? It is a fast paced, 2D shooter of types. I hear TCP/IP is reliable, but UDP might be what I''m looking for in terms of speed... Should I learn WinSock? DirectPlay? I have no idea here... Second, is my approach good? I gathered on my own that we want to send as little as possible, so I figured I''d set up a Client/Server deal, only transmit User Inputs from Client->Server, and only transmit On-Screen object positions/orientations from Server->Client, after the Server has calculated properly. I would like to NOT have seperate client/server programs; In the program you get you have the option of being your own server with the possibility of being dedicated, or connecting to another server. At the most BASIC level, I was thinking of having, hell, a simple BOOL to keep track of whether you are a Client or Server and then skipping/running certain functions accordingly. For example, "Are we a Client? Yes - Skip Movement Calcs, send Input Data Instead. No(server) - Preform Movement Calcs on all players from recieved data and send updated Positions/Orientation. Does this approach check out? If not, could you perhaps recommend someway to do it efficiently? Finally, if you recommend a certain Networking Path to follow (WinSock, DirectPlay, a Networking Wrapper?), could you perhaps take a few minutes to show me a BARE-BONEs example of simple networked app? I mean THE SIMPLEST networking app you can get. Something along the lines of a small Win32 Console App, "Be a Server or Client?", then I can choose ''Server'', call a friend up, give him my IP, and then have him connect to me so we can send small text strings back and forth, and then close the connection. That would be the ideal learning tool, if anything and greatly appreciated, whether you write it yourself or direct me to a pre-written one. I already understand in general about the theory behind networking, I just need a positive direction to go in and a nice, simple example to use as a learning tool to expand upon... Thanks for any and all the help you can provide .

Share this post


Link to post
Share on other sites
Start with TCP because it takes care of a lot of issues for you since you're new. Over a LAN TCP is plenty fast.

If you care, move to UDP later. At this point you're just going to end up using UDP to make a slow version of TCP.

You can find my Winsock class (complete with a couple minor bugs so you don't get a free ride) at the DevZone in the My Source section.

You can also download the complete source (client and server) for Gang Wars which was done in DX7. I believe that's else where on the site in it's own section which you can get to from the main icarusindie.com page.

Ben


IcarusIndie.com [ The Labyrinth | DevZone | Indie Mail | Hosting | Tiberian Merchandise | GameShot | Fun With Cutouts ]


[edited by - KalvinB on January 27, 2003 12:05:23 AM]

Share this post


Link to post
Share on other sites
>> Start with TCP because it takes care of a lot of issues for you since you''re new. Over a LAN TCP is plenty fast.<<

True...but who wants to make a LAN only game. No offence intended, just curious?

>>If you care, move to UDP later. At this point you''re just going to end up using UDP to make a slow version of TCP.<<

Hmmm...I''m gonna have to go ahead and disagree with that. Yes, if you make your own gauranteed delivery method with UDP and send all of your messages for gauranteed delivery, then yes, you''ll probably be slower than TCP''s tried-and-true implementation of the same thing. However, in most games where any amount of action is taking place you do not neeed to send each message as gauranteed. In fact, you rarely need to do that.

Instead, you only send gauranteed messages for important things(Joining, Quitting, Map Change, etc). All of the movement updates and whatnot can be sent un-gauranteed with UDP, which is a MUCH faster process. This can speed up your networking quite a bit.

As far as the Original Poster''s question goes, I''d check out the "Articles & Resources" here first. You''ll find some stuff about Networking there

-John

Share this post


Link to post
Share on other sites
"True...but who wants to make a LAN only game. No offence intended, just curious?"

Since when did it become a good idea to write an MMO on the net to begin with? You don''t start worrying about internet performace until the project works over a LAN. If it doesn''t work flawlessly a LAN you can bet it''s going to be even more screwed up on-line.

You start with TCP and LAN then internet and TCP then if you need to; UDP.

Starting with TCP forces you to work very hard to optimize but at the same time allows you to work on what''s important: your messaging system. Not dicking around with UDP crap.

Once you know your game works, switching to UDP is a lot easier since there''s a heck of a lot less that could be wrong when something inevitably doesn''t work.

Ben


IcarusIndie.com [ The Labyrinth | DevZone | Indie Mail | Hosting | Tiberian Merchandise | GameShot | Fun With Cutouts ]

Share this post


Link to post
Share on other sites
Hey, thanks for the responses and advice! Sounds like TCP/IP for me .

What do you guys think about the other questions? WinSock/DirectPlay/Wrapper? Does my approach sound good? Is there any place I can get a SIMPLE Win32 console Client/Server Chat application? Might be alot to ask someone to quick bang one out quick.. But thanks for the help so far!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It wouldn''t take more than five minutes to do it, but I''m not at home atm.

http://tangentsoft.net/wskfaq/ helped me alot and they have a few examples you might want to look at. Remember to read the lame list

Share this post


Link to post
Share on other sites
quote:
Original post by neonfaktory
What do you guys think about the other questions? WinSock/DirectPlay/Wrapper? Does my approach sound good? Is there any place I can get a SIMPLE Win32 console Client/Server Chat application? Might be alot to ask someone to quick bang one out quick.. But thanks for the help so far!
As it is for learning, I suggest using plain Berkley sockets. Most documentation/tutorials you''ll find will be for them, and you''ll be able to move your implementation easily to other platforms. That boils down to avoiding Windows'' asynchronous sockets and DirectPlay, and do your own wrapper.

As how to do that, you''ll need to focus on the messaging system. Change, if necessary, your game logic to work with a server, but keep that "server" in your game untill you''re satisfied with the design. When you''re there, you will have a better picture of what your network layer needs to cope with.

I have a fancy for threaded networking, and I think that may be a good idea in this case, if you''re avoiding asynchronous sockets. Although threads can be a pain in the a**, keeping all network code separated in it''s own thread, makes it clearer and simpler than trying to intergrate it with the game core.

I don''t think you should worry about TCP vs. UDP now, but it might be worthwhile to consider what design your network code needs to have to support it; such as marking certain data as critical and other as non-critical.


Share this post


Link to post
Share on other sites
You can still create a wrapper that is portable to other OSes and that still makes use of overlapped I/O + completion ports on Windows. No need to go with the lowest common denominator.

Share this post


Link to post
Share on other sites