简体   繁体   中英

Socket.io sync between only two clients

I'm trying to create a game where the browser in the desktop is one view and a mobile device is another view. You use the mobile device as the game controller to make characters in the desktop move. It is similar to chrome.com/supersyncsports.

Using socket.io, what is the best way to sync a mobile device to a desktop client? chrome.com/supersyncsports uses a code to sync the two clients. Are they using something similar to socket.io's namespacing or rooms, where the code is the name of room?

I'm looking for a way to sync the two clients and make sure data is only emitted to the correct device and connection and not all connections. What is the best of achieving this using socket.io?

As film42 said, the code entry is probably the best way to do it, using something like this server side:

socket.on('room', function(room) {
    if(io.sockets.clients(room)>=2){
        socket.emit('error':"too Many connections")
    }
    else{
        socket.join(room);
    }
});

allows you to limit each room to two clients

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM