How to create a P2P chat app for iPhone without using a server? - iphone

Can anyone tell me, is it possible to create an iPhone chat app without using a server. I just need only two connections.

I guess it would be possible by the two devices have to be directly connected (i.e. bluetooth, wifi, etc.). They may therefore discover each other (at an application layers i.e periodically broadcasted UDP packets on a give port?), create a tcp connection (or UDP but in this case you should ensure at application level all the sent messages are actually received..) on the top of which the actual chat protocol can be realized

Related

What is the trick used by some iphone sip apps to communicate with UDP only sip servers?

There are some ios sip applications who are able to communicate with a UDP only SIP Server.
As I know iOS allows only TCP connection to remain open in the background but most of the SIP providers are supporting only UDP.
I have noticed that iOS application 3CXPhone has a "NAT helper mode" and it is able to keep the communication in background with a 3CX Phone system who is UDP only. Dose anyone know what trick do they use? I am developing an SIP app and I have to make it work for the UDP only SIP providers.
I know there are multiple questions regarding UDP socket in background on SO but none of them has a useful answer or the solution proposed there dose not work anymore (starting from iOS 6).
Until now I am aware of 2 possible solutions:
1. Use some GPS events and during that events maintain the socket communication too. After that try to trick apple and get your app in the store.
2. Use a SIP proxy in the middle (B2BUA). But in the 3CXPhone "NAT helper mode" I am not seeing any sip proxy configuration.
If you really need a UDP socket you will need a few things:
UIRequiresPersistentWiFi: to ensure that iOS connects to Wi-Fi and doesn't turn it off after some time (I'm assuming you want Wi-Fi as well, if not just ignore this one)
Play an empty audio in the background in a loop to keep your application active.
Have a timer that pops every ten seconds or so and sends a small (e.g. crlf) message to the server.
The last step is needed to keep the UDP connection open in the network. If you don't send anything often, someone in the network (e.g. a router) will close it.
The empty audio file is the only way to ensure you can do something in the background in short intervals (the ten second timer).
After writing all that: this will consume a lot of battery. Users will not leave your app running for long.
Most modern SIP servers support TCP. You should really spend your time on a TCP solution. The UDP one won't be accepted by your users.

Is there a framework to easily implement server-client or master-slave inter-devcie communication apps?

I want to make a utility app which communicates with other clients running on other devices.
One app becomes the master and waits for slaves. It connects with the slaves and sends them lightweight data in real time. The devices are within 10 meters range of eachother and it is not intended for long distance communication so bluetooth would be ok. Low latency and time synchronisation is very important.
I think GameKit peer to peer would be an option for this? What other options are there? Is there a open source framework that makes this very easy to set up?
I am not an expert but Bluetooth- Wi-fi - Bonjour would be your options I guess. GameKit would be the best option to use.
From Matthijs Hollemans:
GKSession has a method called sendDataToAllPeers:withDataMode:error: that will send the contents of an NSData object to all connected peers. You can use this method to send a single message from the server to all the clients. The message in this case is an NSData object, and what is inside this NSData object is completely up to you.
For peer to peer connection;
A packet is at least 10 bytes. These 10 bytes are called the “header,” and any (optional) bytes that may follow are the “payload.” Different types of packets have different payloads, but they all have the same header structure
You can check this blueetooth game tutorial
Matthijs Hollemans: Snap

communication between smartphone

how can I communicate with another smartphone per example in a game?
I'm developing in objective-c, I need to pass/receive informations about positions of some elements on the screen, but I've not ideas of how i can do this, can you give me some tips? Do i need a physical server with a socket open? and how can i manage the connection?
Thanks for any help.
Jonathan.
Look into the peer-to-peer methods of GameKit. It's designed for multiple devices to communicate with each other. iOS only.
One phone can't readily programmatically talk directly to another phone. Well, you might be able to get phone A to send an email or SMS to phone B, but then phone B's app won't be able to act on the notification. (Since you mention obj-C I assume you're using iOS)
So you'll likely have to have a central server help out. Assuming apps running on both phones. Phone A can make an http request to the server; while phone B polls for a possible response. It can use a comet-like technique to reduce polling overhead.

iPhone (behind cellular NAT) peer-to-peer internet connection with a server

I have an iPhone on a 3G cellular network and a server on the internet and I want them to be able to exchange messages bidirectionally. Sometimes the iPhone makes a request to the Server some other times the Server makes a request to the iPhone. Problem is that the iPhone is behind the NAT of the cellular network and it doesn't have a fixed ip:port , on every new connection the port changes.
I think I have to make a bidirectional socket SO_REUSEADDR/SO_REUSEPORT and make the connection persistent.
The other two solutions are Apple's Push notification and long polling, for now I need an answer for the P2P solution between the iPhone and the Server.
Can you advise me on what I have to do or provide me a working example code where an iPhone can receive messages from a host that is on the internet?
It is a pity that Java is not supported on the iPhone, because the JXTA framework would have solved your issue easily.
What you are looking for is a TURN like implementation of P2P. The Iphone has to initiate the connection to the server to punch the hole in the NAT and yes, it has to be kept alive (even if you investigate more sophisticated implementations like STUNT for NAT traversal).
With TURN, the server has to transmit messages between IPhones, with STUNT, messages are transferred directly between devices, but it is quite complicated to implement properly.
i've been doing a lot of reading up on these things and my understanding is that XMPP is the solution for you. use an open source XMPP server (like openfire) and XMPPframework (an ios module).

Iphone Game Dev Over The Internet

I was wondering is there an easy way to communicate between iphones over the Internet(Not LAN/Bluetooth) or must there be a dedicated server in which all the iphones running an application needs to connect to?
For instance, suppose I'm writing a game which works on the Internet. Once four clients joins a room, game starts. must I implement a server in which every Iphone client connects to (for instance if server was developed on Windows it could be a Service) or is there another way to address this when developing Internet-based application?
Thank you
We have an online game that uses the iPhone (see www.ownthisworld.com if you want an idea of what we have done). Basically we use a php back end that accepts requests and returns xml data to the phone. It works quite well, but it depends on how much data you would be sending and your expected response times. In any event, our architecture of PHP/MySql backend works fine for our needs. By using the normal internet route, you do not have to worry about firewalls so much either.
You'd at the very least need some sort of central match making service so that the iPhones would be able to find each other, which would require some sort of dedicated server.
Secondly, devices on the internet can't always simply do a direct connection with each other. If all of the devices are behind a NAT or a firewall that doesn't allow incoming connections, you'd need a central dedicated server to host the game on. If at least one of the iPhones can accept incoming direct connections, you could have that iPhone host the game for the others.
There are some ways to punch through a NAT, but they're generally pretty horrifying in their complexity, and you'd still need the central match making service to pair up players.