我有一个设备(地址bbbb :: 17:d00:30:76fb)向我的笔记本电脑发送定期数据包,Windows 10,地址2a02:2c40:100:a001:919a:2a07:1a4d:d8bc使用dst_port 61624,包len 8.
这个数据包清楚地到达笔记本电脑,正如Wireshark所见。
332 28.379668 bbbb::17:d00:30:76fb 2a02:2c40:100:a001:919a:2a07:1a4d:d8bc UDP 70 61624 → 61624 Len=8
我的笔记本电脑正在运行以下Python脚本(忽略有关srvIds的内容):
import socket
import sys
NODE_ADDRESS = "bbbb::17:d00:30:76fb"
# Create a UDP socket
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
# Bind the socket to the port
server_address = ('', 61624)
print('starting up on {} port {}'.format(*server_address))
sock.bind(server_address)
numb = 1
while True:
print('\nwaiting to receive message')
data, address = sock.recvfrom(4096)
print('received {} bytes from {}'.format(
len(data), address))
print(data)
srvIdFrom = data[-4] | data[-3] << 8
srvIdTo = data[-2] | data[-1] << 8
print('packet had srvIdFrom {} and srvIdTo {}'.format(srvIdFrom,srvIdTo))
numb = numb + 1
if numb > 120:
numb = 1
if data:
my_bytes = bytearray()
dummySrvId = 98
my_bytes.append(numb)
my_bytes.append(dummySrvId & 0xff) # -4 (offset from end)
my_bytes.append(dummySrvId >> 8) # -3
my_bytes.append(srvIdFrom & 0xff) # -2
my_bytes.append(srvIdFrom >> 8) # -1
#addressTo = (address[0],61624) # reply back, depends on how it is received
addressTo = (NODE_ADDRESS, 61624) #reply to direct node
sent = sock.sendto(my_bytes, addressTo)
#print('sent {} bytes {} back to {} with numb {}'.format(
# sent, my_bytes, addressTo,numb))
srvIdFrom = my_bytes[-4] | my_bytes[-3] << 8
srvIdTo = my_bytes[-2] | my_bytes[-1] << 8
print('return packet had srvIdFrom {} and srvIdTo {}'.format(srvIdFrom,srvIdTo))
在运行此脚本时,它永远不会过去:
starting up on port 61624
waiting to receive message
所以我收到一个数据包,但服务器从不使用它。我知道我做错了什么?
答案 0 :(得分:-2)
I am beyond retarded. The IPv6 address had a subtle mistake, once fixed, this works!