-
-
Save hiway/df70ecd912aa4b33409e68bd92c4efa3 to your computer and use it in GitHub Desktop.
Hello World HTTP server in pyzmq (using ZeroMQ RAW socket) - a Python3.5+ version of http://gist.github.com/hintjens/5480625
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import zmq | |
DEFAULT_PAGE = '\r\n'.join([ | |
"HTTP/1.0 200 OK", | |
"Content-Type: text/plain", | |
"", | |
"Hello, World!", | |
]) | |
DEFAULT_PAGE = DEFAULT_PAGE.encode('utf-8') # Ensure we use bytes, not str. | |
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 | |
response = DEFAULT_PAGE | |
# send Hello World page | |
router.send_multipart([identity, response]) | |
# Close connection to browser | |
router.send_multipart([identity, b'']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment