My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python2.5

# 'Friendly Flow' is a Server Framework for Python 2.5 and up
# Copyright (C) Xaba Software http://www.xaba.nl/
#
# This file is part of 'Friendly Flow'
#
# 'Friendly Flow' is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 'Friendly Flow' is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with 'Friendly Flow'; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

from sys import path
path.insert(0, '..')

from socket import SOL_SOCKET, SO_REUSEADDR
from friendlyflow import Scheduler, flatten, socket, fork, HttpRequest

def handleTcp8000(sock, remoteAddress):
httpRequest = HttpRequest(sock, remoteAddress)
path = yield httpRequest.path()
yield httpRequest.writeAll("you requested %s" % path)
sock.close()

def tcpServer():
listening = socket()
listening.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
listening.bind(('0.0.0.0', 8000))
listening.listen(10)
while True:
sock, remoteAddress = yield listening.accept()
yield fork(flatten(handleTcp8000(sock, remoteAddress)))

def main():
scheduler = Scheduler([flatten(tcpServer())])
scheduler.run()

if __name__ == "__main__":
main()

#is it possible to write a yielding for statement?

Change log

r59 by klaasvanschelven on Jun 24, 2008   Diff
Implemented a (very fragile) proof of
concept webserver which simply echoes the
requested path
Go to: 
Project members, sign in to write a code review

Older revisions

r54 by klaasvanschelven on Jun 24, 2008   Diff
Flatten: testReturnInOutmostGenerator
(his is required to be able to call
flatten at any codepoint)
ReadLine for the AllDataSentFirst case
r53 by klaasvanschelven on Jun 24, 2008   Diff
Added httpserver baseline (file/class
def etc.)
r52 by klaasvanschelven on Jun 24, 2008   Diff
Added 'webserver' example (as of yet
only prints incoming connections
All revisions of this file

File info

Size: 1725 bytes, 50 lines

File properties

svn:executable
*
Powered by Google Project Hosting