I'm trying to use websockify 0.11.0 to take the data from an incoming websocket connection and forward that data to another server.
On one server (172.16.2.5) I have
the following Python application that creates a WebSocket connection to the server running websockify and repeatedly sends a message:
from time import sleep
from websocket import create_connection
while True:
print("Sending...")
ws.send("Hello world")
print("Sent")
sleep(5)
On the 172.16.2.6 server, websockify was started with the following command to forward messages to the 172.16.2.7 server:
./run -v 80 172.16.2.7:33333
On the 172.16.2.7 server, the following Python application is supposed to receive messages from websockify:
import socket, time
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('', 33333))
s.listen()
conn, addr = s.accept()
with conn:
print("Connected by", addr)
while True:
data = conn.recv(11)
print("Received: %s" % data)
time.sleep(5)
When I start the application on 172.16.2.5, it sends the messages with no errors, and prints out the following:
Sending...
Sent
Sending...
Sent
Sending...
Sent
After the application on 172.16.2.5 has started, websockify immediately prints out the following:
172.16.2.5: new handler Process
172.16.2.5 - - [07/Jun/2024 15:40:36] "GET / HTTP/1.1" 101 -
172.16.2.5 - - [07/Jun/2024 15:40:36] 172.16.2.5: Plain non-SSL (ws://) WebSocket connection
172.16.2.5 - - [07/Jun/2024 15:40:36] connecting to: 172.16.2.7:33333
The application on 172.16.2.7 immediately prints out the following after the application on 172.16.2.5 has started:
Connected by ('172.16.2.6', 32906)
But there are a couple of problems. First, the application on 172.16.2.7 blocks on the call to conn.recv(11)
forever until I stop the application on 172.16.2.5. Once the application
on 172.16.2.5 is stopped, the application on 172.16.2.7 finally starts
printing out the "Received:" messages every 5 seconds.
Second, the application on 172.16.2.7 does not receive any data from websockify. It just keeps printing out "Received: b''" (an empty byte string) every 5 seconds. I would expect it to print out "Received: Hello world" every 5 seconds.
Anyone know why websockify isn't sending the data from the 172.16.2.5 application to the 172.16.2.7 application?