Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 900
Ankit Rustagi Avatar asked Sep 30 '14 08:09

Ankit Rustagi


People also ask

Can WebRTC be used on mobile?

Benefits of WebRTC Google wants to enable seamless real-time communication between all consumer platforms, so WebRTC is supported by the latest updates of such browsers on PC, iOS, and Android as Microsoft Edge, Google Chrome, Mozilla Firefox, Safari, Opera, BlackBerry, Vivaldi and Brave.

What is P2P connection?

In peer-to-peer (P2P) networking, a group of computers are linked together with equal permissions and responsibilities for processing data. Unlike traditional client-server networking, no devices in a P2P network are designated solely to serve or to receive data.


3 Answers

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

like image 58
Fattie Avatar answered Oct 04 '22 07:10

Fattie


PeerJS is what you're looking for:

http://peerjs.com

like image 39
hypery2k Avatar answered Oct 04 '22 09:10

hypery2k


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.

like image 24
mattm Avatar answered Oct 04 '22 08:10

mattm