当前位置: 首页>>代码示例>>Python>>正文


Python Connection.receive_packet方法代码示例

本文整理汇总了Python中connection.Connection.receive_packet方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.receive_packet方法的具体用法?Python Connection.receive_packet怎么用?Python Connection.receive_packet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在connection.Connection的用法示例。


在下文中一共展示了Connection.receive_packet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import receive_packet [as 别名]
def main():
    server_port = 30000
    client_port = 30001
    protocol_id= 0x99887766
    delta_time = 0.25
    send_rate = 0.25
    time_out = 10

    connection = Connection(protocol_id, time_out)

    if not connection.start(server_port):
        print("Could not start connection on port {}".format(server_port))
        return 1

    connection.listen()

    while 1:
        if connection.is_connected():
            print('server sending packet')
            packet = [c for c in "server to client"]
            connection.send_packet(packet)

        while 1:
            bytes_read, pack = connection.receive_packet(256)
            if bytes_read == 0:
                break
            print("Received packet from client")

        connection.update(delta_time)
        time.sleep(delta_time)
开发者ID:mitchfriedman,项目名称:PythonServer,代码行数:32,代码来源:server.py

示例2: main

# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import receive_packet [as 别名]
def main():
    server_port = 30000
    client_port = 30001
    protocol_id = 0x99887766
    delta_time = 0.25
    send_rate = 0.25
    time_out = 10

    connection = Connection(protocol_id, time_out)
    
    if not connection.start(client_port):
        print("Could not start connection on port {}".format(client_port))
        return

    connection.connect(Address(a=127,b=0,c=0,d=1,port=server_port))
    connected = False

    while 1:
        if not connected and connection.is_connected():
            print("Client connected to server")
            connected = True

        if not connected and connection.connect_failed():
            print("Connection failed")
            break
        
        packet = [c for c in 'client to server']
        sent_bytes = connection.send_packet(packet)

        while 1:
            bytes_read, pack = connection.receive_packet(256)
            if bytes_read == 0:
                break
            print("Received packet from server")

        connection.update(delta_time)
        time.sleep(delta_time)
开发者ID:mitchfriedman,项目名称:PythonServer,代码行数:39,代码来源:client.py


注:本文中的connection.Connection.receive_packet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。