ToshNeox ToshNeox - 4 months ago 22x
Node.js Question

NodeJS/ not receiving event from client

While trying to setup a simple NodeJS server and client to test something with WebSockets, I've stumbled into something stupid. I'm pretty sure it's something stupid I've done because I've worked with NodeJS/ before and never had this problem.

With the code below, I'm able to receive the 'tick' event from the server on the client, but the server seems unable to receive the 'ping' event from the client. 'tick' was used to make sure server->client worked, and 'ping' to test client->server.

Using latest (1.4.6) and express (4.14.0)


var express = require('express');
var app = require('express')();
var server = require('http').createServer(app);
var sio = require('')(server);
var path = require('path');

app.use(express.static(path.join(__dirname, 'public_html')));

sio.on('connection', (socket) => {
// Store socket ID
var socketID =;

// Log connection
console.log('Connection:', socketID);

// Ping event
socket.on('ping', (message) => {
console.log('Ping:', socketID, '-', (message || '(no message>'));

// Tick event
var tick = function(){
var now = new Date().getTime().toString();
socket.emit('tick', now);
setInterval(tick, 5000);

// Disconnect event
socket.on('disconnect', () => {
console.log('Disconnected:', socketID);

server.listen(4100, () => {
console.log('Listening on :4100');


<!DOCTYPE html>
<title>Websockets Benchmark</title>
<script src="/"></script>
var sio = io();

// Connection event
sio.on('connect', () => {

sio.emit('ping', 'on connect');

// Tick event
sio.on('tick', (time) => {
console.log('Tick', time);

// Error event
sio.on('error', (e) => {


Can't tell if the ping event is taken by, or the following line caused an issue:

console.log('Ping:', socketID, '-', (message || '(no message)'));

Either way, by changing the event name to ev:ping (which is easier to understand anyway), and simplifying that line it's fixed! :)