25.01.2015 Views

with ZeroMQ and gevent - GitHub

with ZeroMQ and gevent - GitHub

with ZeroMQ and gevent - GitHub

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

15<br />

16<br />

17<br />

18<br />

19<br />

20<br />

21<br />

22<br />

23<br />

24<br />

25<br />

26<br />

27<br />

28<br />

29<br />

30<br />

31<br />

32<br />

from <strong>gevent</strong>.pywsgi import WSGIServer<br />

from <strong>gevent</strong>.server import StreamServer<br />

from <strong>gevent</strong>.socket import create_connection<br />

def h<strong>and</strong>le_http(env, start_response):<br />

start_response('200 OK', [('Content-Type', 'text/html')])<br />

print 'new http request!'<br />

return ["hello world"]<br />

def h<strong>and</strong>le_tcp(socket, address):<br />

print 'new tcp connection!'<br />

while True:<br />

socket.send('hello\n')<br />

<strong>gevent</strong>.sleep(1)<br />

def client_connect(address):<br />

sockfile = create_connection(address).makefile()<br />

while True:<br />

line = sockfile.readline() # returns None on EOF<br />

if line is not None:<br />

print "

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!