what type of network programming is necessary in iPhone online multiplayer game? - iphone

I am asking this question as a small part of my question series regarding game programming .
Refer this question as the main one .
Now suppose I want to develop a game on iphone - a simple online multiplayer board game.
Suppose its a casino table.
In the main question ChrisF has tell me of sort of Client - Server architecture for iphone online multiplayer game.
I want to know what sort network programming I have to do for this type of application .
What will be the responsibilities and activities carried out by client and server .
You can provide me link, tutorials or to the point answers , anything will be great help for me and will be really appreciable .
thanks

You'll want to write a socket application running on a server. When you have access to a wifi access point or edge/3g you can send data to it from your iphone application. This server can then handle the incoming data and send an appropriate reply to the people connected.
For server socket programming, take a look at this guide - http://beej.us/guide/bgnet/.
For iphone specific socket programming, take a look at the samples supplied with the Iphone SDK. This link also has some basic information.

A simple online multiplayer board game
Given that the iPhone isn't always connected to the internet, you might need a server to store state. Alternatively you could always stipulate that if one person loses their connection the game finishes.
Client to client would be the obvious choice for the latter. Both clients have a port they listen to, and send the other commands based on the board state. Like almost all online games the obvious choice would be to use UDP as it's fast and compact.
For the server architecture you will of course need some kind of server listening for commands and a game number. It would store your state in a datastore on the server, a mySQL database for example. UDP or even SOAP or JSON over HTTP would be the two obvious choices for this.
This second approach using JSON/SOAP route would be a lot easier for you to get started with, assuming the iPhone has a decent JSON or SOAP library which is not likely. I have no idea about UDP in Objective C, however in C it requires a certain level of knowledge which won't get you something to play with quickly.

As you already said, you will need a server, but you can have two kinds of design:
The server can serve only as a gateway between the players to connect one to each other: it's two uses are, first, to list the running games, and second, to list the IP addresses of the players so that each client will read the IP addresses and connect to them. This will require less bandwidth and processing power for the web server and more for the client which will host the game. In this configuration, one of the clients will act as a server and will send data to the others. If your game has only one of the players playing at a time, and not a huge lot a players, this is what you should use as what you pay is the server's power.
The server can also store all games' states: it might require far more processing power and/or bandwidth depending on your game.
Anyway, most of the time you will want only one machine (which can change during the game as in the first case) to do the processing and the others will only receive the computed data.
To program a networked game, you will need knowledge of sockets (deep knowledge in the first case because you will have to deal with NAT issues, routers blocking the way between clients). The guide to that is Beej's Guide to Network Programming, the number one ressource on this topic, although it doesn't focus on games.
If not too much processing is needed on the WWW server, you could deal with it with server scripting languages like PHP along with MySQL, but you're most likely to use your own server programmed in C++ (or in C). If you use C++, you might want to use an already existing library such as RakNet.
The client will obviously be programmed in Objective-C as it's on the iPhone. I believe there is a good networking framework looking at the number of online games, so you might as well not want to use an external server networking library.
It might be a bit too much for what you want to do, but you could also use the well known Torque Engine.

Related

TCP based decentralised chat app in C

I need to make TCP based decentralised chat app for local network. By decentralised I mean there is no central server. Each entity on a network should have server/client architecture. When app starts it should check which user is online ( already running the app ). My question is how can i check that? Can i do it by trying to connect via connect() function from socket library? I'm new to programming, especially socket programing, so if it's a dumb question sorry in advance.
You should definitely study how other decentralized applications do this. There are lots of techniques.
Each instance of the application should, as part of its server functionality, track the addresses of other instances of the application. Each instance should, as part of its client functionality, keep track of a few instances it can connect to. Prefer instances that have been around for a long time.
The software should include a list of servers that have been running for a long time and are expected to typically be available. You may wish to include a fallback method such DNS, maintained by anyone willing to keep a list of well-known servers offering access through a well-known port. The fallback method can also be IRC or HTTP.
If you want to stay decentralized, you might want to try multicasting or broadcasting a request packet to all hosts on the network to discover other instances of your chat application.
Something similar has been implemented in Pidgin, named Bonjour. It works quite nicely and provides chatting capabilities on a local network. More specifically, it is defined as a Serverless Messaging part of XMPP.
If you are looking for code examples, have a look at one of my projects where I use multicast to discover hosts on the local network that provide a specific service: Headers and implementation.

Network Programming: Nomenclature Questions

So I am looking to get into network programming.
Specifically for a real time strategy game (in Unity 3D). I've done some basic GET and REQUEST stuff before, but I'm curious as to what I will need for doing real time game programming over a network.
My questions about the programming nomenclature are:
-What is the name of programming ("network programming" is too broad) involved in coding real time game networks?
-Can I do real time network programming with JSON or is there another technology I need to use?
-What search terms should I use to research network programming further (as what I've been pulling up has been to broad)?
Thank you!
Update:
Adding to the helpful question below, here is a good link explaining the different types of Authoritative Servers.
http://www.gabrielgambetta.com/fast_paced_multiplayer.html
Unity 4 uses a built-in version of RakNet to achieve network programming, typically referred to as Unity Networking.
Rather than using GET requests or sending JSON messages, you generally use the various Network APIs that Unity offers:
The host starts up with Network.InitializeServer.
Clients connect to the host with Network.Connect.
GameObjects that need to be synchronised across all players should have a NetworkView component attached to them; objects are then synched automatically without needing much effort on your part (for a basic object anyway).
Remote Procedure Calls let you invoke functions on clients.
Data is transferred with UDP packets since things need to happen quickly without ACK packets being sent back and forth, though there are different options to ensure the packets are ordered reliably within Unity if needed.
The Unity Network Reference Guide is a good read.

What's the difference between SIP/XMPP for web conferencing and file-sharing?

I want to setup a personal videoconferencing service for my family, friends and myself. The main problem I have with current options is that they are either closed-source and centralized (GG hangouts, skype) or open-source but not working in corporate environment or in hotels (due to strict firewalling rules and the "Skype is going through, if you want VOIP use that" kind of netadmin reaction).
I have two solutions then. Either setup a STUN/TURN relay server and use XMPP and SIP as I used to, but that would require my friends to setup that too. Or setup a whole VOIP server. 2 solutions come to mind: SIP and XMPP. Though to my knowledge, each of them ultimately uses the (S)RTP/RTCP protocol.
And that's the problem. Out of the specific signaling part used by the two of them, I really can't figure out the difference between them, their typical use case.
I think you're right in that as far as setting up a video conferencing system XMPP and SIP are equivalent. They both are signalling only protocols and the media sessions they set up typically use RTP (although they can both be used to set up any kind of session you want but RTP is the norm).
The biggest problem is also going to be the one you mention about getting video streams out of a corporate firewall. Skype overcomes this obstacle by sending it's media over an SSL connection and is thus able to get through firewalls. Theoretically you could do the same with RTP and in the past I once used openvpn connections with a SIP client to test some audio calls. My experience wasn't great as the audio was very choppy, assumedly as a result of all the extra packaging that is required to get the high volume of small audio packets from one end to the other. That was nearly a decade ago though so perhaps with the better CPU and bandwidth resources available now it would work better.
Personally I think I'd stick with Skype as it's going to be a big hassle to set up your own system. If you were to go ahead with your own the first option I would try would be Asterisk combined with openvpn so that if the clients were behind a firewall or had NAT issues they could connect over it.

How should I implement bi-directional networking between an iPhone application and an Objective-C server-side application?

I'm looking for advice on the best way to implement some kind of bi-directional communication between a "server-side" application, written in Objective-C and running on a mac, and a client application running on an iPhone.
To cut a long story short, I'm adapting an existing library for use in a client-server environment. The library (which runs on the server) is basically a search engine which provides periodic results, and additionally can provide updates for any of those results at a later date. In an ideal world therefore I would be able to achieve the following with my hypothetical networking solution:
Start queries on the server.
Have the server "push" results to the client as they arrive.
Have the server "push" updates to individual results to the client as they arrive.
If I was writing this client to run on another Mac, I might well look at using Distributed Objects to mask the fact that the server was actually running remotely, but DO is not available on an iPhone.
If I was writing a more generic client-server application I would probably look at using HTTP to provide some kind of RESTful interface to searches, but this solution does not lend itself well to asynchronous updates and additionally what I am proposing does not fit well with the "stateless" tennet of REST: I would have to model my protocol so I "created" a search resource that I could subsequently query the state of and I would have to poll for updates to it.
One suggestion someone made was to make use of something like BLIP to provide me with a two-way pipe between the client and the server and implement my own "proxy" type objects for the server-side resources that knew how to fetch data from the server and additionally were addressable so that the server could push updates to them. Whilst BLIP provides the low-level messaging framework needed to communicate bi-directionally it still leaves me with a few questions:
How will I manage the lifetime of the objects on the server? I can have a message type that "creates" a search object, but when should that object be destroyed?
How well with this perform on an iPhone: if I have a persistent connection to the server will this drain the batteries too fast? This question is also pertinent in the HTTP world: most async updates are done using a COMET type hack which again requires a persistent connection.
So right now I'm still completely unsure what the best way to go is: I've done a lot of searching and reading but have not settled on any solution. I'm asking here on SO because I'm sure that there are many of you out there who have already solved this problem.
How have you gone about achieving real-time bidirectional networking between the iPhone and an Objective-C server-side app?

What types of apps are developed today using socket programming?

I've worked in business application development for a while but have never done socket programming. I know that all HTTP transport implicitly involves socket communication but this is all abstracted when using most software frameworks. So I was curious what types of apps developed today involve socket programming?
Any kind of proprietary communication protocol running over UDP or TCP would fit this description. We have a handful of applications that communicate with embedded systems using TCP and UDP, all using specialized protocols.
An application involving networking or network protocols could involve socket programming. This would mean UDP, TCP, peer-to-peer, etc.
Financial companies, especially ones in algorithmic trading area, rely on TCP/IP heavily.
That ranges from third party communication products like Tibco to FIX over TCP sockets to in-house frameworks over UDP/multicast.
Here's what I developped in my own spare time (took me 2 years actually) :
(1) program I called "big chief"
(2) program I called "the manager"
Here's how it works :
First launch the managers on every machine that is configured for that.
Once launched, the big chief asks for dlls to create a list of sites to "suck".
It cut them in "packets" and sends each packet to a "(2) manager"
Each manager has a pool of "workers" (threads). As soon as it gets the list, it activates each thread with one url to "suck". After some time, once all the list is done, the manager make a big "results" packet then send it back to the "big chief".
It can go far further than just "simply" suck urls. (You can define a whole "path" with get and posts, and the cookies follows the path, which means stuff like "going to xx.com, simulate valid button, then go to xx.com/valid.php (with all the cookies and so on set) then simulate something else.)
Yep, it's a mini-google.
I used TCP for "big chief" and "manager" communication with my own protocol and compression before sending.
One of its powerful feature is that you can extend it very easyli. I've used my PC for the "big chief" and 6 other Internet connexions for the managers (including a huge one from my old school). I am able to add as many "managers" as I want :).
PS : Why am I talking about that ? Because I'm proud of it and it's not used at all. It's on my computer, I've sucked a site that is hard to ... suck (pbase.com) and they've probably seen incoming connexions from the States, China, and so on (whereas I'm in France) (yep it does do support public proxies as well)... I'm so proud of a product that is not used at all...