Networking in games?

Member
Posts: 79
Joined: 2002.08
Post: #1
Network programming is a pretty much unknown subject to me. I have done some tests with OpenPlay a long time ago but that's about it.

What options are available on OS X for networking as it relates to games? I know about Open Transport but I'm not sure I want to dig into that.

Then there are sockets, which I don't know anything about really. What would be the best and/or easiest way to implement networking in a game? What kind of protocol is preferable?

Any sample code and /or docs available (other than what's on Apple's site or in the Developer folder)?

KenD

CodeBlender Software - http://www.codeblender.com
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Sockets are good, there's lots of sample code. Don't bother with OpenPlay/NetSprocket or Open Transport. SDL_net might be worth a look if you're into SDL.

Good sockets tut: http://www.ecst.csuchico.edu/~beej/guide/net/html/

Good discussion of how UT handles things, if you're talking about networking for a real-time game: http://unreal.epicgames.com/Network.htm
Quote this message in a reply
Member
Posts: 79
Joined: 2002.08
Post: #3
Never looked at SDL. Is it worth it in that case or should I just try to go the socket route?

I looked at the socket tut stuff at the link above. So these socket calls are basically low level unix calls?
Could the CFSocket stuff be used instead? Do I want to? Would that make it easier or more complicated?

From what I can understand about sockets from the tutorial, it seems pretty easy. Get a file descriptor and send some data. Is that it?!? I'd need an IP address to send to of course.

Of course since I'm using CFM, I'd need to do the function pointer stuff but that should work, right?

So many questions... Shock

KenD

CodeBlender Software - http://www.codeblender.com
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #4
I haven't done much network programming so take this advice with the always popular grain of salt.

Quote:Originally posted by KenD
I looked at the socket tut stuff at the link above. So these socket calls are basically low level unix calls?
Correct.

Quote:
Could the CFSocket stuff be used instead? Do I want to? Would that make it easier or more complicated?
From what I hear sockets are pretty easy to use by themselves so I don't see much point in using CFSocket (which I assume is just a wrapper).
Quote this message in a reply
Member
Posts: 79
Joined: 2002.08
Post: #5
Well, now I know a lot more about sockets than a couple of hours ago Smile

I have got the examples from the tutorial up and running in the terminal and even modified the client a little. And it's working so far Wow

Next step would be do get support for incomplete packages in and working.

This seems almost too easy. I must be missing something... Well, I guess the real trouble is getting it to work in a real time game.

KenD

CodeBlender Software - http://www.codeblender.com
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
CFSockets are just a more complex way of using sockets, don't even bother with them Rasp

Why use CFM? You're X-only with this route, just make your life easy and go to Mach-O.

Yeah, getting stuff working is pretty easy. Testing it rigorously is not, and getting real-time performance is not. The Unreal thingy is a good start for thinking about the issues and some of the solutions though.
Quote this message in a reply
Member
Posts: 116
Joined: 2002.04
Post: #7
Quote:Originally posted by OneSadCookie
CFSockets are just a more complex way of using sockets, don't even bother with them Rasp

I don't know if I'd agree with that - they abstract a TON of socket detail.

Quote:Why use CFM? You're X-only with this route, just make your life easy and go to Mach-O.

I'd certainly agree with that.

Wade
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #8
Here's what I'm doing for udg: There's one class, GameState, which saves everything about the game state. To modify anything, you call a method which takes three parameters: one of an enum of constants of what to change, a new value, and an index. It makes the appropriate change, and if it's a server then it appends the change to the current packet. When you send a game packet, it clears the buffer. To send a complete packet, it simply uses dataWithBytes: to copy the struct which holds everything. And it also knows how to extract data from packets to apply to itself on the client side, and can copy the packet over the game state with a complete packet. I think it might work ok...

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
The hard part is coping with lag, lost clients, &c...
Quote this message in a reply
Member
Posts: 79
Joined: 2002.08
Post: #10
Quote:Originally posted by OneSadCookie
Why use CFM? You're X-only with this route, just make your life easy and go to Mach-O.


Simply just because I haven't got around to convert it to Mach-O. And maybe I'm a bit worried what that is going to lead to. It should be straight forward but you never know...
Maybe I'll give it a shot today and see how it goes.

OS 9 support is not an issue, that just won't happen. Decided that a long time ago.

KenD

CodeBlender Software - http://www.codeblender.com
Quote this message in a reply
Gastropod
Unregistered
 
Post: #11
Quote:Originally posted by OneSadCookie
Sockets are good, there's lots of sample code. Don't bother with OpenPlay/NetSprocket or Open Transport. SDL_net might be worth a look if you're into SDL.


I'm kind of a fan of OpenPlay. You can look at GameGlutton here on iDevGames for an example of using OpenPlay.
You can get it done with sockets of course, but OpenPlay will abstract some difficulties about playing between Macs and PCs. If you are just doing Mac-2-Mac play then perhaps it's not as useful.
Quote this message in a reply
Member
Posts: 79
Joined: 2002.08
Post: #12
I got the latest OpenPlay (which is still over a year old) from cvs. I compiled it but the sample I tried didn't work, returned some error so I figured it might not be much to count on. OP appears to be dead anyway.

KenD

CodeBlender Software - http://www.codeblender.com
Quote this message in a reply
Member
Posts: 79
Joined: 2002.08
Post: #13
Just an update on the OpenPlay stuff. I had forgot to build the module needed and that's why I got an error. It's working fine now.

OpenPlay would definitely make a lot of things easier with the connecting and joining, etc. I'll look into it more. Would save time if I don't need to write all that from scratch myself.

KenD

CodeBlender Software - http://www.codeblender.com
Quote this message in a reply
Member
Posts: 164
Joined: 2002.04
Post: #14
I used OpenPlay for Lugaru networking, and got it playable within a few days, albeit insanely laggy due to a total lack of prediction or anything like that. It also started crashing occasionally; not sure if it's because of Openplay or something stupid in my implementation (considering I'd never tried networking before).

Also do you know if there's any way to have Openplay work without having all the modules and things in the same folder as your project? It seems kinda sloppy to me when I upload games with lots of random stuff in the folder... I like the happy three-item folders: app,data,readme.
Quote this message in a reply
Member
Posts: 79
Joined: 2002.08
Post: #15
I looked over the Oustanding Issues file in the OP folder and some bugs and issues there are a bit worrying. The OPExample1 has some crashing bugs in the interrupt code they haven't been able to resolve so if you have your code based on that maybe you got the same bugs.
That part scares me the most since it's the example I'd like to use if I used OP.

As for file management. I haven't tried this but if you packaged your game in a bundle I'd think you can place the OP libs in the bundle and that way not have lots of files laying around. Should work on OS 9 too.

KenD

CodeBlender Software - http://www.codeblender.com
Quote this message in a reply
Post Reply