def __init__(self, conn=None, family=socket.AF_INET, type=socket.SOCK_STREAM): ''' conn: an existing socket, None (to create a new socket), or False (no socket provided but don't make one yet) family and type default to TCP/IP. Changing them only matters if you don't provide a connection (i.e. it is None). ''' object.__init__(self) self._lock = threading.RLock() self.__refcount = 0 self._proxy_setup = False self.__proxysocket = None self._handlers = [] self.data = '' self.family = family self.type = type if conn is False: #do not use/make a socket at this time async_chat.__init__(self) self.__refcount += 1 AsyncoreThread.start() else: if conn is None: #make a socket async_chat.__init__(self) self.make_socket(family=family, type=type) else: #use an existing socket async_chat.__init__(self, conn) self.__refcount += 1 AsyncoreThread.start()
def __init__(self, conn = None, family = socket.AF_INET, type = socket.SOCK_STREAM): ''' conn: an existing socket, None (to create a new socket), or False (no socket provided but don't make one yet) family and type default to TCP/IP. Changing them only matters if you don't provide a connection (i.e. it is None). ''' object.__init__(self) self._lock = threading.RLock() self.__refcount = 0 self._proxy_setup = False self.__proxysocket = None self._handlers = [] self.data = '' self.family = family self.type = type if conn is False: #do not use/make a socket at this time async_chat.__init__(self) self.__refcount += 1 AsyncoreThread.start() else: if conn is None: #make a socket async_chat.__init__(self) self.make_socket(family = family, type = type) else: #use an existing socket async_chat.__init__(self, conn) self.__refcount += 1 AsyncoreThread.start()
def make_socket(self, proxy=True, family = socket.AF_INET, type = socket.SOCK_STREAM): if getattr(self, '_fileno', None) is not None: self.del_channel() if proxy: proxy = util.GetProxyInfo() self.create_socket(family, type) self.__refcount += 1 AsyncoreThread.start()
def make_socket(self, proxy=True, family=socket.AF_INET, type=socket.SOCK_STREAM): if getattr(self, '_fileno', None) is not None: self.del_channel() if proxy: proxy = util.GetProxyInfo() self.create_socket(family, type) self.__refcount += 1 AsyncoreThread.start()
def main(): fix_logging() AsyncoreThread.start() import wx; a = testapp('../../..') a.toggle_crust() from oscar import protocol oscar = protocol('digsby01', 'no passwords', user = object(), server = ('login.oscar.aol.com',5190)) oscar.Connect() oscar.send_im('digsby04', u'hello world') a.MainLoop()
def start(self): ''' turns this server on, if not already ''' if not self.started: self.started = True self.create_socket(AF_INET, SOCK_STREAM) try: self.bind( self.bind_addr ) # GET IP ADDRESS except Exception, e: self.log_info("failed to bind on (%r, %r)" % self.bind_addr) raise e self.listen(5) AsyncoreThread.start()
def main(): fix_logging() AsyncoreThread.start() import wx a = testapp('../../..') a.toggle_crust() from oscar import protocol oscar = protocol('digsby01', 'no passwords', user=object(), server=('login.oscar.aol.com', 5190)) oscar.Connect() oscar.send_im('digsby04', u'hello world') a.MainLoop()
def main(): fix_logging() AsyncoreThread.start() import wx; a = testapp('../../..') a.toggle_crust() from jabber import protocol global jabber jargs, jkwargs = connection_settings['gtalk'] jabber = protocol(*jargs, **jkwargs) jabber.Connect() a.MainLoop() try: jabber.Disconnect() except: pass AsyncoreThread.join(timeout = None)
def main(): fix_logging() AsyncoreThread.start() import wx a = testapp('../../..') a.toggle_crust() from jabber import protocol global jabber jargs, jkwargs = connection_settings['gtalk'] jabber = protocol(*jargs, **jkwargs) jabber.Connect() a.MainLoop() try: jabber.Disconnect() except: pass AsyncoreThread.join(timeout=None)
return _default_server_manager.stop_serving(pattern, host, port) def shutdown(): global _default_server_manager if _default_server_manager is None: return _default_server_manager.shutdown() _default_server_manager = None if __name__ == "__main__": logging.basicConfig() import AsyncoreThread as AT AT.start() srv = HTTPServerManager() class ClosingHandler(DefaultHandler): def handle(self, client, request): print "closing!" client.push("HTTP/1.1 200 OK\r\n" "Connection: close\r\n" "\r\n" "server has been shutdown") client.close() srv.shutdown() host, port = srv.serve("/close", ClosingHandler, host="", port=0) srv.serve(lambda *a: True, DefaultHandler, host="", port=0) print AT.net_thread.map import time
return return _default_server_manager.stop_serving(pattern, host, port) def shutdown(): global _default_server_manager if _default_server_manager is None: return _default_server_manager.shutdown() _default_server_manager = None if __name__ == '__main__': logging.basicConfig() import AsyncoreThread as AT AT.start() srv = HTTPServerManager() class ClosingHandler(DefaultHandler): def handle(self, client, request): print 'closing!' client.push('HTTP/1.1 200 OK\r\n' 'Connection: close\r\n' '\r\n' 'server has been shutdown') client.close() srv.shutdown() host, port = srv.serve('/close', ClosingHandler, host='', port=0) srv.serve(lambda *a: True, DefaultHandler, host='', port=0)