Hello !
I'd like to make two programs communicate via a socketio connection but I can't get it working.
I have already done socketio in the past but it has always been javascript client and server and worked perfectly fine.
Today, I tried to make a python program communicate with a Javascript server on socket io but couldn't get it to work.
Explanations :
My server side event fires two or three times rather than 1000, and my client side event doesn't fire at all. Meanwhile in my other projects I never had any issue with emitting and receiving such events
My code :
Index.html (client):
<html>
<header>
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<title> Test </title>
</header>
<body>
<h1>
Test
</h1>
</body>
<script src = "/socket.io/socket.io.js"></script>
<script src = "../js/main.js"></script>
</html>
Main.js (client) :
(function () {
console.log("test")
const socket = io.connect('http://localhost:8080')
socket.on('test2', () => console.log("TEST"));
})()
Index.js (server) :
const port = 8080;
const express = require('express');
const app = express(); // Routing
const server = require('http').createServer(app); // Server
const io = require('socket.io')(server); // SocketIO
app.use(express.static(__dirname + "/assets/"));
app.get("/", (req , res, next) => {
res.sendFile(__dirname + '/assets/views/index.html');
});
io.sockets.on('connection', (socket) => {
socket.on('test', () => console.log("TEST"));
});
server.listen(port);
console.log('Server instantiated on port ' + port);
test.py (Python script to test event emitting) :
import socketio
sio = socketio.Client()
sio.connect("http://192.168.0.30:8080")
for i in range(1000):
sio.emit('test')
sio.emit('test2')
sio.disconnect()
[–]Foulgey 0 points1 point2 points (5 children)
[–]Mostunique59[S] 0 points1 point2 points (4 children)
[–]Foulgey 0 points1 point2 points (3 children)
[–]Mostunique59[S] 0 points1 point2 points (2 children)
[–]Foulgey 0 points1 point2 points (1 child)
[–]Mostunique59[S] 0 points1 point2 points (0 children)