def main():
app = QCoreApplication([])
local_ip = QHostAddress('192.168.43.126')
port = 2359
udp_socket = QUdpSocket()
b = QByteArray()
b.append('i0000,0000')
udp_socket.writeDatagram(b, QHostAddress('192.168.43.1'), port)
udp_socket.bind(QHostAddress('192.168.43.126'),port)
while True:
#print('in the while loop')
while udp_socket.hasPendingDatagrams():
#print('has pending datadrams ')
s = udp_socket.readDatagram(10)
print(s)
app.exec_()
if __name__ == '__main__':
main()
这我不工作套接字没有绑定到端口我不知道为什么我需要让服务器等待消息但不使用信号