def __init__(self, host, port):
"""
Object constructor.
:param host: The Frostbite2 server host
:param port: The Frostbite2 server port
"""
asyncore.dispatcher_with_send.__init__(self)
self._buffer_in = ''
self.getLogger().info("connecting")
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
asyncore.dispatcher_with_send.connect(self, (host, port))
self._frostbite_event_handler = None
self._frostbite_command_response_handler = None
####################################################################################################################
# #
# PUBLIC API #
# #
####################################################################################################################
python类dispatcher_with_send()的实例源码
def send_command(self, *command):
"""
Send a command to the Frosbite server and return the command
id which can be used to find the matching reply later on.
"""
self.getLogger().info("command : %s " % repr(command))
if len(command) == 1 and type(command[0]) == tuple:
words = command[0]
else:
words = command
request = EncodeClientRequest(words)
[sequence, words] = DecodePacket(request)[2:]
self.getLogger().debug("sending command request #%i: %s " % (sequence, words))
asyncore.dispatcher_with_send.send(self, request)
return sequence
####################################################################################################################
# #
# OTHER METHODS #
# #
####################################################################################################################
def __init__(self,sock,time_fn):
self.time_fn = time_fn
asyncore.dispatcher_with_send.__init__(self,sock)
def __init__(self, consumer, query, host, port=43):
asyncore.dispatcher_with_send.__init__(self)
self.consumer = consumer
self.query = query
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
def __init__(self,*name,**args):
DnsRequest.__init__(self, *name, **args)
asyncore.dispatcher_with_send.__init__(self)
# XXX todo
if 'done' in args and args['done']:
self.donefunc=args['done']
else:
self.donefunc=self.showResult
#self.realinit(name,args) # XXX todo
self.async=1
def __init__(self, sock, core):
asyncore.dispatcher_with_send.__init__(self, sock=sock)
ProtoMixin.__init__(self)
QObject.__init__(self)
self.core = core
self.idb_path = GetIdbPath()
self.send_packet({
'kind': 'new_client',
'input_file': GetInputFile(),
'idb_path': GetIdbPath(),
'pid': os.getpid(),
})
print("[continuum] Connected.")
def handle_close(self):
asyncore.dispatcher_with_send.handle_close(self)
print("[continuum] Connection lost, reconnecting.")
self.core.create_client()
def __init__(self, sock, server):
# We need to use old-style init calls here because asyncore
# consists of old-style classes :(
asyncore.dispatcher_with_send.__init__(self, sock=sock)
ProtoMixin.__init__(self)
self.input_file = None
self.idb_path = None
self.server = server
self.project = server.core.project
self.server.clients.add(self)
def handle_close(self):
self.server.clients.remove(self)
self.server.update_idb_client_map()
print("[continuum] A client disconnected.")
asyncore.dispatcher_with_send.handle_close(self)
def __init__(self, conn, certfile):
self.socket = ssl.wrap_socket(conn, server_side=True,
certfile=certfile,
do_handshake_on_connect=False)
asyncore.dispatcher_with_send.__init__(self, self.socket)
self._ssl_accepting = True
self._do_ssl_handshake()
def __init__(self, conn, certfile):
self.socket = ssl.wrap_socket(conn, server_side=True,
certfile=certfile,
do_handshake_on_connect=False)
asyncore.dispatcher_with_send.__init__(self, self.socket)
self._ssl_accepting = True
self._do_ssl_handshake()
def __init__(self, conn, certfile):
self.socket = ssl.wrap_socket(conn, server_side=True,
certfile=certfile,
do_handshake_on_connect=False)
asyncore.dispatcher_with_send.__init__(self, self.socket)
self._ssl_accepting = True
self._do_ssl_handshake()
def __init__(self, async_socket, handlers, settings):
"""async echo handler based on asyncore.dispatcher_with_send
:param async_socket: the socket object
:param handlers: handlers mapping
:param settings: settings config
"""
self.logger = logging.getLogger()
self.__handlers = handlers
self.__settings = settings
asyncore.dispatcher_with_send.__init__(self, sock=async_socket)
def __init__(self, conn, certfile):
self.socket = ssl.wrap_socket(conn, server_side=True,
certfile=certfile,
do_handshake_on_connect=False)
asyncore.dispatcher_with_send.__init__(self, self.socket)
self._ssl_accepting = True
self._do_ssl_handshake()
def __init__(self, host, port, handler_ctx, close_handler=None):
self.__host = host
self.__port = port
self.__close_handler = close_handler
asyncore.dispatcher_with_send.__init__(self)
self._socket_create_and_connect()
time.sleep(0.1)
self.rsp_buf = b''
self.handler_ctx = handler_ctx
def __init__(self, conn, certfile):
self.socket = ssl.wrap_socket(conn, server_side=True,
certfile=certfile,
do_handshake_on_connect=False)
asyncore.dispatcher_with_send.__init__(self, self.socket)
self._ssl_accepting = True
self._do_ssl_handshake()
def __init__(self, conn, certfile):
self.socket = ssl.wrap_socket(conn, server_side=True,
certfile=certfile,
do_handshake_on_connect=False)
asyncore.dispatcher_with_send.__init__(self, self.socket)
self._ssl_accepting = True
self._do_ssl_handshake()
def __init__(self, conn, certfile):
asyncore.dispatcher_with_send.__init__(self, conn)
self.socket = ssl.wrap_socket(conn, server_side=True,
certfile=certfile,
do_handshake_on_connect=False)
self._ssl_accepting = True
def __init__(self, sock, interface, server):
asyncore.dispatcher_with_send.__init__(self, sock=sock)
self._datastore = ModbusDataStore(interface.di, interface.co, interface.ir, interface.hr)
self._modbus = ModbusProtocol(self.send, self._datastore)
self._server = server
self._set_logging_context(interface)
self.log.info('Client connected from %s:%s', *sock.getpeername())
def __init__(self, markov, sock, remote_server, remote_port):
self.markov = markov
asyncore.dispatcher_with_send.__init__(self, sock)
msock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
msock.connect((remote_server, remote_port))
self.msock = LocalProxy.ToMTunnelServer(markov, self, msock)
def __init__(self, markov, sock, oSock):
self.read_buffer = ''
self.markov = markov
asyncore.dispatcher_with_send.__init__(self, oSock)
self.client = sock
def __init__(self, markov, sock):
self.read_buffer = ''
self.markov = markov
#self.msock = MTunnelServer.ToRemoteServer(markov, self, msock)
self.msock = None
self.state = 0
asyncore.dispatcher_with_send.__init__(self, sock)
self.state_lock = threading.RLock()
def __init__(self, markov, sock, oSock):
self.markov = markov
asyncore.dispatcher_with_send.__init__(self, oSock)
self.client = sock
def __init__(self, conn, certfile):
self.socket = ssl.wrap_socket(conn, server_side=True,
certfile=certfile,
do_handshake_on_connect=False)
asyncore.dispatcher_with_send.__init__(self, self.socket)
self._ssl_accepting = True
self._do_ssl_handshake()
def __init__(self, host, port, packet_queue=None):
asyncore.dispatcher_with_send.__init__(self)
self.log = logging.getLogger("RavagedDispatcher")
self._buffer_in = ''
self.packet_queue = packet_queue if packet_queue else Queue()
self.log.info("connecting")
self.create_socket(AF_INET, SOCK_STREAM)
self.connect((host, port))
####################################################################################################################
# #
# PUBLIC API #
# #
####################################################################################################################
def __init__(self, console, host, port, password, keepalive=False):
asyncore.dispatcher_with_send.__init__(self)
self.console = console
self._host = host
self._port = port
self._password = password
self.keepalive = keepalive
self._buffer_in = ''
self.authed = False
self.server_version = None
self.last_pong_time = self.last_ping_time = time.time()
self._handlers = set()
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect( (self._host, self._port) )
def __init__(self, console, host, port, password, packetListener):
asyncore.dispatcher_with_send.__init__(self)
self.console = console
self._host = host
self._port = port
self._password = password
self._packetListener = packetListener
self.isAuthed = False
self.keepalive = True
self.readBuffer = ""
self.console.info("Starting RCON for game server %s:%s" % (host, port))
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((self._host, self._port))