I have written a client server app that connect two iphones using bonjour. My problems is that when both devices start broadcasting and listening using bonjour they find each other at the same moment and both of them connect as a client of each other. How can I avoid this scenario? I am already checking if my app is connected as a server to the other app, but since that happens simultaneously I always connect as a server and client at the same time.
looking into ur case ; 1 solution is that u can make ur device on which app is hosted and gotta serve as server make that devices tcb as passive open so it can only listen on particular port/frequency and client can be programed to be in active open state so it can send request to server.
Related
I want to run a server on Windows Phone 8. It is important that the server keeps running even if the user opens another app or the screen lock turns on. Relying on an internet connection is not an option. It should work in a local network.
UseCase: The server is needed for a multiplayer game. The idea is that one player starts a local server. After that, all players (including the player who starts the local server) can connect to this server using a webbrowser. The server delivers html and responds to ajax calls.
It seems that PeriodicTask and ResourceIntensiveTask do not fit my needs. Is that correct? How can I run an app in the background that is always listening for incoming tcp connections?
I don't know a clean way. But if you're happy with a hack: You could use the Geolocator. This blog gives a step by step guidance: How to create application which executes in the background on Windows Phone 8?
As most of the hacks, this brings some problems and questions (probably more than I mention here):
If the user turns off the GPS, your server won't be reachable anymore.
I don't know how strict Microsoft is with what you can publish on their store.
No way to do this on Windows Phone.
Im developing an iPhone app with client-server design, the server manage client connection with sockets and keep an array of all the currently connected clients.
This way i get persists connection between client and server, and i can send messages from the server to the clients when ever i need.
My problem is on the client side, the iPhone user. every time the phone get locked the connection is lost so i need to re-connect and re logging again when the user unlock the iPhone.
Is this the way to go? Or am I doing it wrong? please help..
A RESTful protocol may be more suitable for mobile use.
I am writing mutliplayer game and thought I would create two instances of GKSession. One session set to GKSessionModeServer and the other to GKSessionModeClient. The server is properly reported when I call peersWithConnectionState: on the client peer and each session has different peer ids. But when I try to connect to the server I receive the message session:connectionWithPeerFailed:withError: with the error description "Failed while pending outgoing invitation.".
Using two GKSessions works when Wi-Fi is available. I am afraid that there is some limitation with Bluetooth that disallows this but I am not sure. I could rewrite the code to use a single GKSession on the server but I would rather not code special cases if I know that someone else got it working with two instances.
If I turn off both Wi-Fi and Bluetooth i get the error "Network not available." which I don't get if either is turned on. This makes me believe it won't work when there is another iPhone is nearby either.
I rewrote the code so I only create one GKSession on the hosting device and send data between the server and the local client directly without using the GKSession. I could finally test this with two devices and they properly connect to each other. So the lesson is to have only one GKSession on the host and it will work with Bluetooth as well as Wi-Fi.
are there any services running by default on an iphone that would let another ip address communicate with it if the iphone's ip is known?
Yes, technically, you can. There are a couple of issues though:
Mobile IP addresses usually change
When the phone is in sleep mode, its network interface is probably not reachable.
So I don't think you can rely on that for initiating a communication with the phone.
There aren't many options out of the box on a non jail-broken phone. However, you can write your own client application that runs on the phone. It accepts or initiates the remote connection.
And in that case, the protocol is entirely up to you.
If you jailbreak your phone, you can install the OpenSSH package and have SSH and SFTP access to your phone.
I don't know exactly what you want to do with your app, but you can consider create a thread detached from the main one (using gcd) and use it to send/receive informations from a server using JSON objects for example. Sure you can use sockets and write a client or something like that.
I suggested a new thread because you can put it running forever (on a enterprise app, I don't know if Apple will approve a thread running on an App for AppStore).
I had to develop an app with a consistent client/server relationship and it was the way I got it working.
I want to be able to send files from an iPhone app to a computer. What would be the easiest way of doing this?
I've made simple server client programs before, but in those, the client has always needed to connect to the server before being able to receive messages from it. There is an app for the iPhone called iSimulate, where you put a server on a Mac (the iPhone simulator), and then you use the iSimulate app of an iTouch or iPhone to send touch events to the server. This app does not require you to type in an ip-address. Instead it presents a list of available computers that have this server up and running.
How exactly is this being done? Can a server broadcast a message over a network, w/o anyone being connected to the server? How does that work? How does a client listen for that broadcast?
Here's a video of the app I'm talking about:
http://www.youtube.com/watch?v=N3Qpd1ycZh4
alt text http://a1.phobos.apple.com/us/r1000/051/Purple/7b/07/70/mzl.mvwjifyc.320x480-75.jpg
That app may be using Bonjour.
I've seen similar apps use a peer-to-peer Bluetooth connection to exchange files between a iPhone and a desktop.