Meteor Server Websockets

爱⌒轻易说出口 提交于 2019-12-05 22:05:39

The following code is for opening a Socket in Meteor on Port 3003. It convert the data from the socket (sendet from client) to a JSON-Object. So this means, the following code is a socket, which receive JSON.

Fiber = Npm.require('fibers')

// server
Npm.require('net').createServer(function (socket) {
    console.log("connected");

    socket.on('data', function (data) {

        socket.write("hello!");

        var o = JSON.parse(data.toString());
        console.log(o);


        Fiber(function() { 
            console.log('Meteor code is executing');
            //=> Meteor code
        }).run();
        //console.log(data.toString());
        //socket.close();
    });
})

.listen(3003);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!