def somecoroutine(): mysocket = Socket() # cogen's socket wrapper yield mysocket.connect(('www.google.com',80)) fh = mysocket.makefile() yield mysocket.sendall("GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n") #~ result = yield fh.readline() result = yield mysocket.recv(10240) print result
def some_stuff_to_keep_sched_alive(): from cogen.core.sockets import Socket s = Socket() s.bind(("localhost", 8000)) s.listen(1) yield s.accept()
def dispatch(self): socket = Socket() address = (self.host, self.port) socket.bind(address) socket.listen(16) log(20, 'Listening on %s:%i' % address) while 1: client_socket, client_address = yield socket.accept() log(20, 'Connection from %s:%s' % client_address) self.scheduler.add( self.serve_to_client, args=(client_socket,), )