Is that possible?
I’m writing a web-admin interface for a network-system. I need to listen to a specific UDP port and show it in browser. Can I do that in javascript?
Also; any other ideas are welcomed.
early-edit: Here’s another idea:
I have php and perl support at server-side. JS can call a php script to start listening, which will also call a perl script, which has an endless listener loop and collects the received messages into a sink variable. In theory; JS will be polling a PHP script every 2 seconds, get the sink variable and show it on browser/html.
But; how can a php script reach/read that sink variable? And, how or when will the perl script stop?
For the first part, using a file as a sink is a terrible idea; I’ll be receiving 10 string messages per second and also reading and then clearing file contents every 2 seconds. Not to mention the file lock mechanisms…
For the second part: i should put timeout somewhere but; where?
edit: Yes, I can choose where the listening will happen (server or client).
edit2: Why do I want to listen for UDP messages on a specific port and show it on browser:
The project I’m working on has some special sensors activated by some bussiness-specific-keys, these sensor devices are network-enabled and I have programmed them to send a UDP network broadcast message containing biz-key-info whenever they sense something.
There are lots of these devices on same network, and the web-admin interface should have a page where user can see what is happening in real-time or almost-real-time (~5 second delay is acceptable, that is why I had the poll-every-2seconds idea at my early-edit).
edit3: I have also found this: ActiveSocket which is an ActiveX component but; as predicted it didnt work on Firefox and has no documentation about it’s html+JS part.
The simpelst solution would be a Flash-Brigdem, since in Javascript there is no way to directly connect to a socket.
I’ve done something like that some time ago you can download the full source here. You can run simpleserver.py(requires python3) and then access the index.htm via localhost, in order to test it.
Also note, Flash’s security model wants an XML-Document on port 843, it will send
to the socket.
You then should respond with something like:
If you don’t have anything running on Port 843 it will send the same request to the port you are trtying to connect to. But only after the 843 request has timed out.
There are some other security “features”, but you can read about those in the Adobe docs.