arduinoWebSockets icon indicating copy to clipboard operation
arduinoWebSockets copied to clipboard

[Request] Please provide a working example of Socket.IO server

Open ithieund opened this issue 3 years ago • 3 comments

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.

ithieund avatar Jun 01 '22 02:06 ithieund

You should search the Node js socketio server elsewhere. It is for arduino.

Here is a link for socketIO with Nodejs

zekageri avatar Jun 14 '22 07:06 zekageri

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.');
    });
});

Links2004 avatar Jun 14 '22 13:06 Links2004

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

ithieund avatar Oct 11 '22 07:10 ithieund