Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set a web socket server (not client) within iOS and Android devices?

I am investigating if it is possible to set a "web socket server" at a mobile device (different than the common approach of"web socket server at a backend").

In order to do that I am searching a method for iOS and Android devices to accept WebSocket requests.

Side note, I am not so sure if the security design of the mobile operating systems allow that or not.

Is there any method to set the web socket servers at mobile devices? (If yes, one step further is there any method that can be used with react-native?)

like image 773
Mehmet Kaplan Avatar asked Oct 16 '22 00:10

Mehmet Kaplan


1 Answers

Kind of. To answer your actual question: No. You cannot create a (multiplatform) webserver inside of react*. To answer the question I think you might have: Yes. You can do direct client-to-client communication in React.

If you're trying to create a webserver in React, I can imagine two use cases(I could totally be missing your point, if so, I'm very sorry).

Use Case 1 - Talking to a server

This one is trivial. Websocket clients and servers are the same thing once everything is initialized. Except for a few exceptions with keepalive messages and precedence, you can create a websocket connection a react app that it effectively identical to a websocket connection to a server.

Use Case 2 - Client to Client communication

If you're trying to allow client devices to talk to each other, and you don't want to have to pass messages through your own server, then you need WebRTC. Named 'Web Real Time Communication', it does exactly what you might expect.

The mdn docs are a great place to get started. WebRTC allows for data streams between arbitrary clients on the network, without a server. It seems like the protocol was intended for streaming videos between peers, but it can be used for anything.

*

You can create webservers and web-server like behavior in react, but it is done in a platform-specific method. However, projects like this and this have frameworks that allow for you to create various other peer-to-peer communication streams.

like image 188
Carson Avatar answered Oct 19 '22 02:10

Carson