Const EXPRESS = require (' Express '); Const HTTP = require (' http '); Const URL = require (' URL '); Const WebSocket = require (' ws '); Const APP = Express (); /** * WebSocket Server Example * Frame: Https://github.com/websockets/ws */ App.use (function (req, res) { Res.send ({msg: "Hello"}); }); Const SERVER = http.createserver (APP); Noinspection Jsannotator Const WSS = new Websocket.server ({Server}); function Testwebsocketserverapi () { Wss.on (' connection ', function connection (WS, req) { Const LOCATION = Url.parse (Req.url, true); Const IP = req.connection.remoteAddress; Const PORT = req.connection.remotePort; Console.log (IP + "" + port); Ws.on (' message ', function incoming (message) { Console.log (' Received:%s ', message); }); Ws.on (' Close ', function (params) { Console.log (' Params:%s ', message); }); Ws.send (' something '); }); Server.listen (8080, function listening () { Console.log (' WebSocket Listening on%d ', server.address (). Port); }); Const WSS = new Websocket.server ({port:8081}); Wss.on (' connection ', function connection (WS) { Ws.on (' message ', function incoming (message) { Console.log (' Received:%s ', message); }); Ws.send (' something '); }); } |