示例#1
0
def run(**kwargs):
    servconn = ServerConnection(network=kwargs['network'])
    MessageInterpreter.register_default_actions()

    while True:
        Action.actions = Action.actions + MessageInterpreter.action_insertion_queue
        MessageInterpreter.action_insertion_queue = []

        messages = servconn.receive_messages()
        MessageInterpreter.process_messages(messages)

        if not servconn.registered:
            irc.register_nick_and_username()
            servconn.registered = True
示例#2
0
def run(**kwargs):
    servconn = ServerConnection(network=kwargs['network'])
    MessageInterpreter.register_default_actions()

    while True:
        Action.actions = Action.actions + MessageInterpreter.action_insertion_queue
        MessageInterpreter.action_insertion_queue = []

        messages = servconn.receive_messages()
        MessageInterpreter.process_messages(messages)

        if not servconn.registered:
            irc.register_nick_and_username()
            servconn.registered = True
示例#3
0
def main():
    """
    Main function to fetch args, connect to server, find info in file and disconnects from server
    """
    try:
        ip_address, wildcard, numeric_id = ArgManager().passed_args
        c = ServerConnection(host=ip_address)

        GrepImpl(root_dir=c.cd, wildcard=wildcard,
                 numeric_id=numeric_id).process()

        c.disconnect()

    except Exception as err:
        print("=== Error ===\n{}: {}".format(err.__class__, str(err)))
示例#4
0
class RequestHandler(object):
    def __init__(self, factory, host, port, sock):
        self.factory = factory
        self.conn = ServerConnection(sock)

    def handle(self):
        try:
            data = self.conn.read()
            print data
            handler = self.factory.make_handler(**data)
            handler.conn = self.conn
            res = handler.execute()
        except Exception as e:
            logger.error(e.message)
            res = {"error": True, "message": e.message}
        self.conn.send(res)
示例#5
0
文件: handler.py 项目: ptbrodie/tcpy
class RequestHandler(object):
    """
    Abstraction for handling a request to a TCPServer instance.
    """

    def __init__(self, factory, host, port, sock):
        self.factory = factory
        self.conn = ServerConnection(sock)

    def handle(self):
        try:
            data = self.conn.read()
            handler = self.factory.make_handler(**data)
            handler.conn = self.conn
            res = handler.execute()
        except Exception as e:
            logger.error(e.message)
            res = {"error": True, "message": e.message}
        self.conn.send(res)
示例#6
0
 def __init__(self,
              config: Config = Config,
              storage: Storage = Storage(),
              recovery: bool = False) -> None:
     self._recovery = recovery
     self._conn = ServerConnection(config)
     self._id: int = self._conn.server_id
     self._server_num = len(config.SERVER_NAMES)
     self._loop = asyncio.get_event_loop()
     self._storage = storage
     self._voted_for_me: Set[int] = {}
     self._message_sent: Dict[int, Message] = {}
     self._message_resend_timer: Dict[int, asyncio.Task] = {}
     self._election_timer: Optional[asyncio.Task] = None
     self._heartbeat_timer: List[asyncio.Task] = []
     self._apply_notifier: Optional[asyncio.Event] = None
     self._membership_change_queue = asyncio.Queue()
示例#7
0
文件: handler.py 项目: ptbrodie/tcpy
 def __init__(self, factory, host, port, sock):
     self.factory = factory
     self.conn = ServerConnection(sock)
示例#8
0
from connection import ServerConnection
from handleConnection import handleConnection

if __name__ == "__main__":
    my_socket = ServerConnection()  #Crea el socket

    my_socket.CreateConnection(
        "", 8080)  #Conexion, con IP local y puerto que va a escuchar

    print("[+] Waiting for incoming connections on port: ",
          my_socket.server_port)

    my_socket.Listen()  #Se mantendra escuchando

    my_conn = my_socket.AcceptConnection()  #Acepta la conexion, si una llega

    handleConnection(my_socket)

    # my_socket.send_data("Hi this is server")
    # print (my_socket.receive_data())
    #my_conn.close()

    my_socket.close()
示例#9
0
def servconn():
    return ServerConnection.get()
示例#10
0
 def __init__(self, factory, host, port, sock):
     self.factory = factory
     self.conn = ServerConnection(sock)