Kevin Van Ryckegem
Kevin Van Ryckegem

Reputation: 1945

How to detect a server in the network using JS?

Basically, I want to make a peer to peer architecture, using JavaScript (Ionic).

Since, JS cannot create sockets/etc; a NodeJS server has to be introduced between the clients; acting as the Socket.IO server between the clients.

The problem with this, is that the Socket.IO (NodeJS) server would need to be automatically found within the local network -- by the clients (instead of hardcoded/configured).

Are there any ways to implement such a thing; or alternatives to this architecture?

Thanks for the help!

Upvotes: 1

Views: 833

Answers (1)

rsp
rsp

Reputation: 111466

Are there any ways to implement such a thing; or alternatives to this architecture?

Currently your architecture is using a browser app plus a Node app that users need to have on their network just to create TCP connections.

What you can do instead is create an Electron app that combines a Node app, a browser app, and a browser itself. See:

With Electron you can write your frontend code almost the same way as for the regular browser, but you can use the entire Node API including the TCP sockets so there will be no need to create a separate Node app and to search for that app in the network. This can greatly simplify your architecture.

Note: this is not an answer to the first part of the question: "How to detect a server in the network using JS?" but to the second part of the question: "Are there any ways to implement such a thing; or alternatives to this architecture?" Detecting the servers on the local network with client-side JavaScript will not be easy - and in fact it shouldn't be even possible because websites being able to scan your LAN for active services would be a serious problem for privacy and security.

Upvotes: 2

Related Questions