Node.js client for a socket.io server

前端 未结 5 2006
天涯浪人
天涯浪人 2020-11-28 20:22

I have a socket.io server running and a matching webpage with a socket.io.js client. All works fine.

But, I am wondering if it is possible, on another machine, to ru

5条回答
  •  醉酒成梦
    2020-11-28 21:18

    After installing socket.io-client:

    npm install socket.io-client
    

    This is how the client code looks like:

    var io = require('socket.io-client'),
    socket = io.connect('localhost', {
        port: 1337
    });
    socket.on('connect', function () { console.log("socket connected"); });
    socket.emit('private message', { user: 'me', msg: 'whazzzup?' });
    

    Thanks alessioalex.

提交回复
热议问题