Keep StreamSocketListener running in background on Windows Phone 8 - sockets

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.

Related

Is it possible to build a VPN without an actual server?

After searching online most places have stated that it is required to have a server to build a VPN, but I was wondering if it is possible to do it and have mobile devices connect to a dummy server? Without actually having something constantly running on a server.
I am currently developing an app that will make users connect to a VPN that blocks access to all sites.
Define "server". If you are worried about cost of hardware/power, bear in mind that a server is just a computer that hosts applications or data for clients to access and interact with. I currently have a Dell latitude e6400 running as an owncloud server in my basement. If you need something for testing you could simply utilize whatever old hardware you have laying around to set up the server side for your app to connect to, and turn it on whenever you are testing the app.

iphone: a local server to test my app

the app that i'm developing, needs to interact with a server, to accomplish some operations: save user's data, retrieve data about other users, services and so on...
before paying to rent some space on a server, i'd like to test my app making it interact with a server located on my computer, simulating a real a LAMP server as a localhost.
did you ever tried to do the same? can you suggest me a LAMP server that i can use locally?
do you suggest any other solution in place of the one i'm seeking?
thanks for help
While the server is running make your requests to your own IP address. I'm fairly confident this will work while you are using the simulator, and likely it will also work from an app.
In terms of finding LAMP server software for the mac... you should check out MAMP which allows you to simulate a server on your mac.

testing socket communication offline as a simulation

Whenever having to test my app which basically is some kind of communication via sockets with external devices, the device itself has to be available and connected.
I would like to ask,if there is a way to do the testing offline in some kind of simulation mode?
For instance, redirecting the socket communication to some kind of stored file. And the file itself is a log of a previous session with the real device stored in an appropriate structure. Of course one could only simulate a recorded session, but that would help a lot already.
thanks!
You should have a look at netcat. If you have a record of your "session" in a file, you can use nc to "play it back" on a socket with something like:
nc -l -p port_number < your_file
You can then connect to that port number with telnet and you'll see the session data coming in.
(You can do it the other way around too, i.e. have nc connect to your app and replay the session.)
Don't know iphone, but having a local client, (or server), app. as a simulator is very common on other platforms. It's especially useful if the peer app is under development as well - having a simulator often surfaces protocol bugs at both ends, (as well as in the simulator:).
Given an app spec that includes the protocol, but no peer yet, I usually start work on the simulator first - it gives me time to get experience with the protocol in an non-critical, non-deliverable way while the customer is still bolting on changes to the main app UI :)
Rgds,
Martin

if I have an iphone's IP address is there anyway I can communicate with it?

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.

Secure iPhone-Desktop Connection

Background
There are a lot of App Store released iPhone apps that require an IP based server on the desktop so that the iPhone can connect to the desktop as a client. For example, there are many programs that emulate a keyboard, touchpad, or Apple remote on the iPhone so that a desktop computer can be controlled over wifi. However, many of these applications get around writing their own server by requiring the user to install some VNC server variant.
Question
What is the best way to implement a secure (encrypted) IP server on a desktop (Mac and Windows platforms) that allows for simple two way message passing between itself and an iPhone client on a wifi network?
Sample Use Case
An event on the desktop causes the desktop to push a small image or text to the iPhone. An event on the iPhone causes a short text message to be pushed to the desktop. Any single event can happen at any time (doesn't appear synchronized to the user).
1st Follow-Up Question
Would this type of project be best handled using something like XML or JSON over HTTP? Or is there a better protocol, like BEEP or Bonjour(XMPP)?
What is the best way to implement a secure (encrypted) IP server on a desktop (Mac and Windows platforms) that allows for simple two way message passing between itself and an iPhone client on a wifi network?
Not sure if there is a "best" way, but much code is already available to do xyz-over-HTTPS (TLS/SSL). In that case, the "xyz" can be any web-based message exchange protocol, such as XML, JSON, etc. via REST or SOAP, etc.
If you want to be able to push events to a non-jailbroken iPhone you can't do it other than via Apple's Push Server which causes a notification to the client program if it is running or otherwise displays an alert of some kind to the user.
Typical architecture has those notifications handled by the client program as an indication it should go and get some data from the server - Apple insist we do not regard the notifications as trusted delivery.
I suggest a read of this article on using Bonjour and local networking, whilst it's iPhone to iPhone it should apply to desktop OS/X also.