Skip to content

Instantly share code, notes, and snippets.

@malexer
Created January 28, 2014 10:02
Show Gist options
  • Save malexer/8664997 to your computer and use it in GitHub Desktop.
Save malexer/8664997 to your computer and use it in GitHub Desktop.
Hello World HTTP server in pyzmq (using ZeroMQ RAW socket) - a Python version of http://gist.github.com/hintjens/5480625
import zmq
DEFAULT_PAGE = '\r\n'.join([
"HTTP/1.0 200 OK",
"Content-Type: text/plain",
"",
"Hello, World!",
])
context = zmq.Context()
router = context.socket(zmq.ROUTER)
router.router_raw = True
router.bind('tcp://*:8080')
while True:
msg = router.recv_multipart()
identity, request = msg
# send Hello World page
router.send_multipart([identity, DEFAULT_PAGE])
# Close connection to browser
router.send_multipart([identity, ''])
@mtasic85
Copy link

mtasic85 commented Dec 8, 2019

This should fix the issue:

DEFAULT_PAGE = '\r\n'.join([
    "HTTP/1.0 200 OK",
    "Content-Type: text/plain",
    "",
    "Hello, World!",
]).encode()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment