dangerChihuahua007
dangerChihuahua007

Reputation: 20915

One way web socket communication?

I was reading about the Python websocket-client library and realized that, to receive data, we have to start a connection:

from websocket import create_connection
ws = create_connection("ws://echo.websocket.org/")
print "Received " + ws.recv() + "..."

What if I just need a one-way connection? Say a Python script is running on my laptop, and it periodically sends messages to a local web server.

To receive messages, the web server would have to start a connection, but starting a connection requires a URL to connect to. My Python script is not a web server, so it lacks a URL. How could the web server receive messages from the script?

I tried to let the server listen for clients to connect with it via

ws = websocket.WebSocket()
while 1:
  print 'received "' + ws.recv()

However, I get an error.

in _recv
    bytes = self.io_sock.recv(bufsize)
error: [Errno 107] Transport endpoint is not connected

That error output leads me to believe that the server needs to connect in order to receive.

Upvotes: 0

Views: 2582

Answers (1)

koper89
koper89

Reputation: 655

If you would want one way connection to the server, you could just listen on plain socket or use UDP or use HTTP requests ore any other TCP protocol.

Upvotes: 1

Related Questions