Created
January 28, 2014 10:02
-
-
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
This file contains 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
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, '']) |
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
there seems to be some error in line 24 of this code while using it in python 3.3.3
error - "Type error - can't use unicode, use send_string" instead.
i tried doing this but doesn't work.