arduinoWebSockets
arduinoWebSockets copied to clipboard
[Request] Please provide a working example of Socket.IO server
Hello @Links2004 I could not find any example code of the socket.io server in Nodejs. Can you add that snippet inside the test folder?
Thank you.
You should search the Node js socketio server elsewhere. It is for arduino.
some example code that I had used in the past for testing.
const io = require('socket.io')(8888);
io.on('connection', (socket) => {
console.info('[' + socket.id + '] new connection', socket.request.connection.remoteAddress);
var cb_test = 0;
socket.on('-cb-test', function() {
socket.emit('-no-cb-test');
socket.emit('-cb-test', cb_test++, function(id) {
console.log('cb-test OK', id);
});
});
socket.on('reconnect', function() {
console.warn('[' + socket.id + '] reconnect.');
});
socket.on('disconnect', () => {
console.error('[' + socket.id + '] disconnect.');
});
});
Thank you!
On Tue, Jun 14, 2022 at 8:36 PM Markus @.***> wrote:
some example code that I had used in the past for testing.
const io = require('socket.io')(8888);io.on('connection', (socket) => { console.info('[' + socket.id + '] new connection', socket.request.connection.remoteAddress);
var cb_test = 0; socket.on('-cb-test', function() { socket.emit('-no-cb-test'); socket.emit('-cb-test', cb_test++, function(id) { console.log('cb-test OK', id); }); }); socket.on('reconnect', function() { console.warn('[' + socket.id + '] reconnect.'); }); socket.on('disconnect', () => { console.error('[' + socket.id + '] disconnect.'); });});— Reply to this email directly, view it on GitHub https://github.com/Links2004/arduinoWebSockets/issues/753#issuecomment-1155197921, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABAFS26C6QWTCOM4CCTHKR3VPCDGJANCNFSM5XPNJ5ZA . You are receiving this because you authored the thread.Message ID: @.***>
-- Sent from my iPhone