Пример #1
0
def testRegister():
    tcpCliSock = socket(AF_INET, SOCK_STREAM)
    tcpCliSock.connect(ADDR)
    request = TransferProtocal_pb2.RequestType()
    request.request = TransferProtocal_pb2.RequestType.REGISTER_REQ

    data = request.SerializeToString()
    sendDataToServer(tcpCliSock, ADDR, data)

    request = TransferProtocal_pb2.Account()
    request.account = "hrhtrd4"
    request.password = "******"

    sendDataToServer(tcpCliSock, ADDR, request.SerializeToString())

    # data = tcpCliSock.recv(BufferSize)
    # ReplyCode = TransferProtocal_pb2.ResultType()
    # ReplyCode.ParseFromString(data)
    #
    # if ReplyCode.result == TransferProtocal_pb2.ResultType.REGISTER_RES:
    data = receiveDataFromServer(tcpCliSock, ADDR)
    tcpCliSock.send("OK".encode())
    result = TransferProtocal_pb2.RegisterRes()
    result.ParseFromString(data)
    #print(str(result.hasSucceed),str(result.error))

    tcpCliSock.close()
Пример #2
0
def RequestProcess(client, address, DBHandlerIndex, HandlerPool):
    try:
        gameLogic = GameBusicness(HandlerPool[DBHandlerIndex])

        # 设置超时时间
        client.settimeout(MaxDelayTime)
        # 接收数据的大小
        buf = client.recv(BufferSize)

        request = TransferProtocal_pb2.RequestType()
        request.ParseFromString(buf.strip(b' '))

        service = ServiceAvailable[request.request]
        service(client, address, gameLogic)
    # 超时后退出
    except socket.timeout:
        Log('[%s] : [ %s:%i ] time out' % (ctime(), address[0], address[1]))
    except ConnectionResetError:
        Log('[%s] : [ %s:%i ] actively disconnected' %
            (ctime(), address[0], address[1]))
    except Exception:
        Log('[%s] : [ %s:%i ] unknow error happened' %
            (ctime(), address[0], address[1]))
    finally:
        # 关闭与客户端的连接
        client.close()
Пример #3
0
def testLogin():
    tcpCliSock = socket(AF_INET, SOCK_STREAM)
    tcpCliSock.connect(ADDR)
    request = TransferProtocal_pb2.RequestType()
    request.request = TransferProtocal_pb2.RequestType.LOGIN_REQ

    data = request.SerializeToString()
    sendDataToServer(tcpCliSock, ADDR, data)

    request = TransferProtocal_pb2.Account()
    request.account = "hrhtr4"
    request.password = "******"

    sendDataToServer(tcpCliSock, ADDR, request.SerializeToString())

    data = receiveDataFromServer(tcpCliSock, ADDR)
    tcpCliSock.send("OK".encode())
    result = TransferProtocal_pb2.LoginRes()
    result.ParseFromString(data)
    #print(str(result.hasSucceed),str(result.error))

    tcpCliSock.close()
Пример #4
0
def testDeletaArchive():
    tcpCliSock = socket(AF_INET, SOCK_STREAM)
    tcpCliSock.connect(ADDR)
    request = TransferProtocal_pb2.RequestType()
    request.request = TransferProtocal_pb2.RequestType.DELETE_ARCHIVE_REQ

    data = request.SerializeToString()
    sendDataToServer(tcpCliSock, ADDR, data)

    request = TransferProtocal_pb2.Account()
    request.account = "hrhtr4"
    request.password = "******"

    sendDataToServer(tcpCliSock, ADDR, request.SerializeToString())

    data = receiveDataFromServer(tcpCliSock, ADDR)
    tcpCliSock.send("OK".encode())
    result = TransferProtocal_pb2.ArchiveOpRes()
    result.ParseFromString(data)
    ##print(str(result.hasSucceed), str(result.operation))

    tcpCliSock.close()
Пример #5
0
# test

from Protocal.generate import TransferProtocal_pb2

request = TransferProtocal_pb2.RequestType()
request.request = TransferProtocal_pb2.RequestType.REGISTER_REQ
data = request.SerializeToString()

result = TransferProtocal_pb2.ResultType()
result.result = TransferProtocal_pb2.ResultType.REGISTER_RES

account = TransferProtocal_pb2.Account()
account.account = "dfsefefsf"
account.password = "******"
account.data = "gdrlgrjmijgg的距离高考家里人".encode()

registerRes = TransferProtocal_pb2.RegisterRes()
registerRes.hasSucceed = True
registerRes.error = TransferProtocal_pb2.RegisterRes.INVALIDATED_ACCOUNT

archiveOp = TransferProtocal_pb2.ArchiveOpRes()
archiveOp.hasSucceed = False
archiveOp.operation = TransferProtocal_pb2.ArchiveOpRes.ADD
archiveOp.data = "dijgim规模i然后554632".encode()