I am trying to connect python client using python-socketio with nodejs express server using socketio. I am able to connect python client with python server using python-socketio. I have already verified the versions and according to version chart it should work.
In NodeJS, I am using "socket.io": "^4.7.4" In Python, I am using "python-engineio==4.8.2" and "python-socketio==5.11.0"
Server Code
// Server Code
import * as dotenv from 'dotenv'
import express, { Request, Response } from 'express'
import { createServer } from 'node:http'
import { Server, Socket } from "socket.io";
import cors from 'cors'
//App Varaibles
dotenv.config()
//intializing the express app
const app = express();
//using the dependancies
app.use(cors());
app.use(express.json())
const server = createServer(app);
const io = new Server(server, {
cors: {
origin: "*",
methods: ["GET", "POST"]
}
});
app.get('/', (req: Request, res: Response) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket: Socket) => {
console.log('a user connected');
socket.on('disconnect', () => {
console.log("user disconnected");
});
});
//exporting server
module.exports = server;
// Running Server
require("dotenv").config();
const server = require(".");
const PORT = process.env.PORT || 3000
//Listing to the app and running it on PORT 5000
server.listen(PORT, async () => {
console.log(`listening on port ${PORT}`)
})
Python Client
# Python client
import socketio
sio = socketio.Client(logger=True, engineio_logger=True)
@sio.event
def connect():
print('connection established')
@sio.event
def my_message(data):
print('message received with ', data)
sio.emit('my response', {'response': 'my response'})
@sio.event
def disconnect():
print('disconnected from server')
sio.connect('http://localhost:5000')
sio.wait()
can you dump the sid's of socket client from both server and client and see if its matching.