★ TouchArcade needs your help. Click here to support us on Patreon.

General Network Programming

06-19-2009, 12:11 AM
#1
Joined: Jan 2009
Location: Canada
Posts: 463
General Network Programming

I'm about to implement some networking protocols in a project, and I'm wondering what pitfalls or caveats I might run into.

1) basic setup: if I send datagrams to a server from the iphone, can the server contact the iphone back over UDP?
1a) can the server contact a phone initially, using only its IP or do some carriers (or all carriers) block certain types of traffic?
1b) can I make a direct tcp connection between two iphones over a cell network (same question about blocking/filtering, I guess)?

2) What kind of protocol would you use for a game that has a medium latency tolerance? (500-1200ms ish) I want to implement TCP between connected peers playing the game. Is that reasonable? UDP sometimes scares me with words like "can lose packets", and I've never written a commercial-grade communication library before. I want TCP because this game depends heavily on getting ALL data sent to it, and in order.

3) I want to implement a game registration server, where new clients register their hosted games, and other clients can query the server to be matched up with someone who's hosting a game. I think this should be done in UDP with a fault-tolerant protocol. I think this is the case because all communication with this server should be very small, and I want it to scale well - TCP is limited to the number of sockets that you can open locally (not scaling up into 10,000s very well), and the tcp protocol just seems like an unnecessary burden on my poor dedicated server if the game gets too popular.


4) fallback: if some phones CAN connect to each other via direct peer-to-peer TCP connections, but others can't, should I also implement (possibly on another server) a sort of relay program whereby all clients talk to the server instead of each other? That way people should be guaranteed to be able to connect to it, and therefore nobody should have connection problems (but I might have server bandwidth/usage problems, not to mention TCP socket limitations if I go that way)...


anyway, I feel a little lost in how to decide once and for all how to structure my network protocol.

please help, if you can.

Developer, Cat in a Box Games!
Blue Defense: Second Wave! - $2.99
Blue Attack! - $1.99

Fastar! - $1.99
Red Conquest! - $0.99
06-19-2009, 12:14 AM
#2
Joined: Jan 2009
Location: Canada
Posts: 463
ooh, I almost forgot to ask:

when you switch cell towers, do you get a new IP?

Developer, Cat in a Box Games!
Blue Defense: Second Wave! - $2.99
Blue Attack! - $1.99

Fastar! - $1.99
Red Conquest! - $0.99