使用javascript从浏览器连接到TCP Socket

我有一个vb.net应用程序打开一个套接字并监听它。

我需要使用在浏览器上运行的javascript通过此套接字与该应用程序进行通信。那就是我需要在这个套接字上发送一些数据,以便正在监听这个套接字的应用程序可以获取该数据,使用一些远程调用做一些事情并获取更多数据并将其放回我的javascript需要的套接字上在浏览器中阅读并打印。

我试过,socket.io,websockify但没有一个被证明是有用的。

因此,问题是,我正在尝试甚至可能吗?有没有办法在浏览器中运行的javascript可以连接到tcp套接字并发送一些数据并在其上侦听以在套接字上获得更多数据响应并将其打印到浏览器。

如果可能的话,有人可以指出正确的方向,这将有助于我确定目标。


阿波罗的战车
浏览 6840回答 3
3回答

凤凰求蛊

见jsocket。我自己没用过。自上次更新至今已超过3年(截至2014年6月26日)。*使用闪光:(从文档:<script type='text/javascript'>&nbsp; &nbsp; // Host we are connecting to&nbsp; &nbsp; var host = 'localhost';&nbsp;&nbsp; &nbsp; // Port we are connecting on&nbsp; &nbsp; var port = 3000;&nbsp; &nbsp; var socket = new jSocket();&nbsp; &nbsp; // When the socket is added the to document&nbsp;&nbsp; &nbsp; socket.onReady = function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; socket.connect(host, port);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; }&nbsp; &nbsp; // Connection attempt finished&nbsp; &nbsp; socket.onConnect = function(success, msg){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(success){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Send something to the socket&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; socket.write('Hello world');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('Connection to the server could not be estabilished: ' + msg);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; }&nbsp; &nbsp; socket.onData = function(data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('Received from socket: '+data);&nbsp; &nbsp;&nbsp; &nbsp; }&nbsp; &nbsp; // Setup our socket in the div with the id="socket"&nbsp; &nbsp; socket.setup('mySocket');&nbsp; &nbsp; &nbsp; &nbsp;</script>
打开App,查看更多内容
随时随地看视频慕课网APP