Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make arbitrary TCP connection from browser [duplicate]

My web application needs to connect to a local device on the network to get data.

The device has a static IP address and communicates via the P03 protocol. When I connect with Telnet, the device returns a plain text in my console.

I need to do the same thing with JavaScript in-browser. When a user clicks a button, it should connect to 192.168.0.1:8000 via TCP and display the received text data on the page.

The problem is that is a web application. Is it possible to do client-side?

(I'm also willing to accept other suggestions besides JavaScript.)

like image 781
Vinicius H Avatar asked Oct 15 '25 09:10

Vinicius H


1 Answers

Unfortunately, you cannot connect to just any TCP socket. The browser can make connections, but it has to be one of these protocols:

  • HTTP (HTTP[S] 1.0/1.1/2)
  • Web Socket (another application protocol actually running on top of HTTP)
  • WebRTC (intended for peer-to-peer, can be used for client-server communication as well, but not useful here)

One way to do this is to run a proxy of sorts. You need to make a proxy that accepts Web Socket connections from browsers, and then relays the sent/received data to this TCP server. The downside is that this requires a server.

Another way is to make a browser extension. See also: https://stackoverflow.com/a/17567373/362536

like image 110
Brad Avatar answered Oct 17 '25 00:10

Brad