socket.io on connection
io.on('connection', (socket) =>{
console.log(`Connecté au client ${socket.id}`)
})
socket.io on connection
io.on('connection', (socket) =>{
console.log(`Connecté au client ${socket.id}`)
})
socket io query
// Client side
const socket = io({
query: { token: 'cde' }
});
// Server side
io.on('connection', (socket) => {
let token = socket.handshake.query.token;
// Do something...
});
how to check whether the user is online or not using socket.io
const users = {};
io.on('connection', function(socket){
console.log('a user connected');
socket.on('login', function(data){
console.log('a user ' + data.userId + ' connected');
// saving userId to array with socket ID
users[socket.id] = data.userId;
});
socket.on('disconnect', function(){
console.log('user ' + users[socket.id] + ' disconnected');
// remove saved socket from users object
delete users[socket.id];
});
});
simple socket.io chat
npm install socket.io
socket only connection
import socket #server
a = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = 'host ip '
port = 'port'
a.bind((host,port))
a.listen(5)#5 is the no. of client at a time
socketclient,address = a.accept()
print('got a connetion from',address)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us