Created
July 29, 2012 04:20
-
-
Save hatone/3196029 to your computer and use it in GitHub Desktop.
echo serverとか。
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 cyclone.web | |
class MainHandler(cyclone.web.RequestHandler): | |
def get(self): | |
self.write("hello, world") | |
Application = lambda: cyclone.web.Application([(r"/", MainHandler)]) |
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 socket | |
host = socket.gethostbyname('localhost') | |
port = 8080 | |
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
socket.bind((host,port)) | |
socket.listen(1) | |
print 'wating for connetion ...' | |
(client_sock, client_addr) = socket.accept() | |
client_sock.send("server: connetion start \n\n") | |
print 'connnection start' | |
while True: | |
msg = client_sock.recv(1024) | |
msg = msg.rstrip() | |
if msg == "bye": | |
client_sock.send("server:connetion end \n\n") | |
print "connection end" | |
break | |
else: | |
client_sock.send("server :%s \n" % msg) | |
print "client: %s" %msg | |
client_sock.close() | |
socket.close() |
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 tornado.ioloop | |
import tornado.web | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Hello, world") | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment