示例#1
0
    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()
示例#2
0
    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()
示例#3
0
    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()
示例#4
0
    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()
示例#5
0
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()
示例#6
0
    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()
示例#7
0
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()
示例#8
0
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)
示例#9
0
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)
示例#10
0
文件: server.py 项目: niterain/digsby
    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
示例#11
0
文件: server.py 项目: sgricci/digsby
        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)