0
节点服务器与ws
模块代码:为什么我无法连接到websocket?
show = console.log
WS = require('ws').Server
wss = new WS port: 8080
wss.on 'connection', (ws) ->
show 'a connection'
ws.on 'message', (message) ->
show 'received: %s', message
ws.send 'something'
我可以连接在同一台服务器上运行下面的代码的WebSocket, 它给了"a connection"
:
WS = require 'ws'
ws = new WS 'ws://localhost:8080'
但是,当我从浏览器运行这些代码行,有没有respose:
s = new WebSocket('ws://184.82.253.196:8080');
s.send('nothing');
什么问题,我该如何解决它?