本文整理汇总了Python中connection.Connection.send_packet方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.send_packet方法的具体用法?Python Connection.send_packet怎么用?Python Connection.send_packet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.send_packet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import send_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)
示例2: main
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import send_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)