Ankit Rustagi
Ankit Rustagi

Reputation: 5637

peer to peer communication between mobile app and pc browser

I am working on a project where i need my mobile application to talk to my web browser on a pc, where both devices are connected over wifi. The app would send data which would be received by the computer browser followed by some client side code execution. The browser then may send some feedback.

My initial approach is to make the app talk to an endpoint which in turn talks to client side of the browser (javascript).

What could be the best approach to do this ?

Update

I am not sure if Socket.io is a possible solution since it requires a server to be hosted. Is it possible to solve this using sockets ?

Upvotes: 10

Views: 4435

Answers (4)

Fattie
Fattie

Reputation: 12336

You've now edited your question to mention P2P. That's quite hard to achieve PHONE TO BROWSER (i.e., by hard I mean 6 to 12 man-months of work - and/or plain not possible). However in MOST situations you can instantly (ie "one line of code on each platform") resolve the problem by using a service like pubnub. Much as nobody has back-ends anymore and everything is just done with parse.com or game center, networking like you mention is now just done with pubunb (or any competitor).

This is an extremely common use case problem - and everyone just uses PubNub as mentioned below or one of its competitors.


These days it couldn't be easier, just use pubnub.com

It's the world's biggest data-messaging service for a reason!

There's essentially no other realistic approach, it's so simple - a few lines of code.

enter image description here

Upvotes: 3

hypery2k
hypery2k

Reputation: 1691

PeerJS is what you're looking for:

http://peerjs.com

Upvotes: 1

hypery2k
hypery2k

Reputation: 1691

So short answer would be: A real peer-to-peer (P2P) communication is currently not possible with all browsers. So instead you have the following options:

  1. App + Server with a WebUI (maybe)
  2. App + Chrome App (Chrome Apps can start an web server, see http://www.devworx.in/news/misc/chrome-apps-can-now-run-a-web-server-135711.html)
  3. App + WebApp with Plugin (Flash, Silverlight or Java)

I personally would prefer solution 1.

Upvotes: 3

mattm
mattm

Reputation: 5949

You need a server. If you consider this problem strictly from the typical firewall point of view, a PC or a mobile device are going to ignore connections unless they initiate the connection themselves. So neither the PC nor the mobile device can start a connection with the other.

My understanding is that web browsers do not support standard sockets within javascript. You can use the analagous websocket, but sockets and websockets are not directly compatible.

You can setup a simple server on the PC, and have this server relay messages between the mobile device and the PC browser. Both the mobile device and the PC browser connect to the server. This is basically what an external service will do for you.

Upvotes: 2

Related Questions