question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Socket.io Tutorial "Chat" is broken

See original GitHub issue
  • report a bug
  • request a feature

Current behaviour

Following the current tutorial version on the socket.io documentation to build a small chat system doesn’t work at all.

Steps to reproduce (if the current behaviour is a bug)

The steps beginning with setting up a basic express server are fine, also adding socket.io to that http server and the connection-event is fine. When it comes to adding the html snippet for the socket.io-client and establishing the connection, it breaks. First of all, the file is not accessible on the express server, so I replaced it with the cdn version. Now it tries to connect, but fails again, probably because it’s trying to reach the socket on a different path (socket.io-1.2.0.js:2 GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1483818339831-18 404 (Not Found)), the tutorial states that the socket is available on /.

Debugging the sockets with 2 different chrome extensions also doesn’t work, they are also not able to establish connections to both of these paths.

Expected behaviour

Tutorials should contain a working example, to allow beginners (like me) to quickly gain experience.

Setup

  • OS: Windows 10
  • browser: Chrome
  • socket.io version: current/latest

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Rewriting the tutorial from scratch should help here.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
darrachequesnecommented, Jan 10, 2017

@max06 I think the issue lies in the app.listen(3000);. According to the reference:

The app.listen() method returns an http.Server object and (for HTTP) is a convenience method for the following…

// Current (does not work)
var express = require('express');
var app = express();

var server = require('http').createServer(app);
var io = require('socket.io')(server);
// ...
app.listen(3000);

// solution1 (which is what is suggested in the tutorial, if I'm not mistaken)
var express = require('express');
var app = express();

var server = require('http').createServer(app);
var io = require('socket.io')(server);
// ...
server.listen(3000);

// solution2
var express = require('express');
var app = express();

var server = app.listen(3000);
var io = require('socket.io')(server);

Also, you should be able to replace <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script> with <script src="/socket.io/socket.io.js"></script>.

0reactions
darrachequesnecommented, Jan 10, 2017

You’re welcome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Socket.io Chat Tutorial not functioning properly
I decided to go with a small chat app to break the ice. The tutorial I am following is directly from the socket.io...
Read more >
A real time web chat with socket.io | by Simone Ricci - Medium
On socket.io website, the “get started” tutorial shows how to build a basic real time web ... Let's split our chat into different...
Read more >
Create a Secure Chat Application with Socket.IO and React
This tutorial shows you how to create a real-time chat application using JavaScript and Socket.IO.
Read more >
Introduction | Socket.IO
Although Socket.IO indeed uses WebSocket for transport when possible, it adds additional metadata to each packet. That is why a WebSocket client ...
Read more >
How to Build a Real-time Chat App with React, Node, Socket ...
Normally, using HTTP requests, the server cannot push data to the client in real time. But using Socket.io, the server is able to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found