donglu5728 2009-09-30 14:36
浏览 50
已采纳

使用Javascript在客户端计算机上侦听套接字

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.

  • 写回答

5条回答 默认 最新

  • duansha8115 2009-09-30 14:53
    关注

    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

    <policy-file-request/>
    

    to the socket. You then should respond with something like:

    <?xml version="1.0"?><cross-domain-policy>
            <allow-access-from domain="*" to-ports="*" />
            </cross-domain-policy>
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂