示例#1
0
def serve():
    port = 50050
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    print('Spartan server started on port {}.'.format(port))   
    chat_rpc.add_ChatServerServicer_to_server(ChatServicer(), server)
    chat_rpc.add_UserServicer_to_server(UserServicer(), server)

    server.add_insecure_port('[::]:' + str(port))
    server.start()
    try:
        while(True):
            time.sleep(_ONE_DAY_IN_SECONDS)
    except(KeyboardInterrupt):
        server.stop(0)
        print('[Spartan] Server Shutdown')
示例#2
0
    def server_initialize(self, address, port):
        try:
            server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

            # use the generated function `add_CalculatorServicer_to_server`
            # to add the defined class to the server
            rpc.add_ChatServerServicer_to_server(ChatServer(), server)
            while port in self.ports:
                port += 1
            server.add_insecure_port(address + ':' + str(port))
            server.start()
            servers.append(server)
            self.ports.append(port)
            self.redis.set('ports', json.dumps(self.ports))
            return address, port
        except:
            pass
示例#3
0
    def NuevoMensaje(self, tipo, cliente, mensaje):
        # tipo = 0 -> Cliente envió
        # tipo = 1 -> Cliente recibió

        if tipo == 0:
            self.ultimoMensaje += 1

        self.chats[cliente][1][tipo].append(mensaje)


if __name__ == '__main__':
    if len(sys.argv) < 3:
        print(
            "[Error] Al ejecutar el programa se debe indicar el hostname y puerto de escucha."
        )
        print("[Info] Ejemplo de ejecución: python server.py localhost 12345.")
        exit(0)

    host = sys.argv[1]
    puerto = int(sys.argv[2])

    server = grpc.server(futures.ThreadPoolExecutor())
    rpc.add_ChatServerServicer_to_server(ChatServer(), server)

    print("[Info] Servidor inicializado en la dirección:",
          host + ":" + str(puerto))

    server.add_insecure_port(host + ":" + str(puerto))
    server.start()
    while True:
        time.sleep(1800)
if __name__ == '__main__':

     # Read config file
    with open("config.yaml", 'r') as ymlfile:
        cfg = yaml.load(ymlfile)
        port = cfg['port']
        maxCachelimit = cfg['max_num_messages_per_user']
        RateLimitperUser = cfg['max_call_per_30_seconds_per_user']

    chatSet = {}
    validGroups = {}
    ratelimiter = {}

    grp1 = cfg['groups']['group1']
    grp2 = cfg['groups']['group2']
    addGroup(grp1,"group1")
    addGroup(grp2,"group2")

    # create a gRPC server

    server = grpc.server(futures.ThreadPoolExecutor(max_workers=int(10)))
    rpc.add_ChatServerServicer_to_server(ChatServer(chatSet,validGroups,ratelimiter,maxCachelimit,RateLimitperUser), server)

    print('Starting server. Listening at {}'.format(port))
    server.add_insecure_port('[::]:' + str(port))
    server.start()
    # Server starts in background (another thread) so keep waiting
    while True:
        time.sleep(64 * 64 * 100)
示例#5
0
        self.LruDict.append(request.message)
        if len(self.LruDict)>5:
            self.LruDict.pop()
        print(self.LruDict)
        return chat_pb2.Empty()
        



filepath = "config.yaml"
data = yaml_loader(filepath)
port = data.get('port')
address = data.get('address')
#print(port)
#print(address)
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
chat_pb2_grpc.add_ChatServerServicer_to_server(
    ChatServer(), server)
print('Starting server. Listening on port 3000.')
server.add_insecure_port(address + ':' + str(port))
server.start()
try:
    while True:
        time.sleep(86400)
except KeyboardInterrupt:
        server.stop(0)


# if __name__ == '_main_':
#     serve()