Can the server be used with another client? #4388
-
I can't connect to socket.io server via browser native class WebSocket. To Reproduce Create basic socket.io Hello world and simple new WebSocket() connection in browser Socket.IO server version: Server import express from 'express';
import http from 'http';
import { Server } from 'socket.io';
const app = express();
app.get('/', (req, res) => {
res.send('<h1>Hello world</h1>');
});
const server = http.createServer(app);
const io = new Server(server);
io.on('connection', (socket) => {
console.log('a user connected');
});
server.listen(parseInt(SERVER_PORT, 10), () => {
console.log('listening on port', SERVER_PORT);
}); Socket.IO client version: Client const connection = new WebSocket(
`${window.location.protocol === 'https' ? 'wss' : 'ws'}://${process.env.REACT_APP_SERVER}:${
process.env.REACT_APP_PORT
}`,
'json'
); Expected behavior Platform:
Additional context
|
Beta Was this translation helpful? Give feedback.
Answered by
darrachequesne
Jun 6, 2022
Replies: 1 comment 1 reply
-
No, you won't be able to connect via plain WebSocket. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
darrachequesne
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No, you won't be able to connect via plain WebSocket.
Reference: https://socket.io/docs/v4/#what-socketio-is-not