4.4.1: client not receiving events upon connection #4278
-
Server code: const express = require('express')
const http = require('http')
const { Server } = require('socket.io')
const APP_HOST = process.env.APP_HOST || '192.168.0.100'
const APP_PORT = process.env.APP_PORT || 8081
const app = express()
const server = http.createServer(app)
const io = new Server(server, {
cors: {
origin: "*",
methods: ["PUT", "GET", "POST", "DELETE", "OPTIONS"],
}
})
io.on('connect', socket => {
console.log('New connection ' + socket.id)
setTimeout(() => socket.emit('message', 'well hello there'), 500) // STATEMENT A
socket.emit('message', 'well hello there') // STATEMENT B
})
server.listen(APP_PORT, APP_HOST, () => {
console.log(`Listening on ${APP_HOST}:${APP_PORT}`)
}) Client code: <!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/socket.io.js"></script>
<script type="text/javascript">document.addEventListener('DOMContentLoaded', function () { var socket = io('ws://192.168.0.100:8081'); socket.connect(); });</script>
</head>
<body></body>
</html> Problem: Statement A seems to "work" somewhat - at least client receives the message. Statement B, however, does NOT work at all - client receives nothing but "2probe" and stuff, although it SHOULD work, according to official examples (here, see the second block). Obviously, I want this to work without dirty timeout hacks. Absolutely no idea what might be the issue. Any help is appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi! I can't reproduce: https://github.com/socketio/socket.io-fiddle/tree/issues/socket.io/4278 Could you please check? |
Beta Was this translation helpful? Give feedback.
-
Solved. |
Beta Was this translation helpful? Give feedback.
Solved.
Client actually receives both messages, but first one never shows up in Firefox network debugger for some reason.
It appears to be a Firefox issue.