Qt Write to UDP Socket on Linux Machine and Windows Read from Socket with Python -


=========== Update: =========== < / P>

Now I am using Broadcast IP 10.6.0.3 and a higher port, 5789. I can see the traffic in Windows Network Monitor, but still can not find Python to read it.

=== ======================================== ====

I have a Linux machine on which a hello message is writing a UDP socket using the IP address 10.6.0.2 Qt and QuadSpocket socket. I also have a Windows machine that I want to read the 'Hello' message through Python. With my QT code, I can see that the data is being written, however, the Python program on Windows always sits on "Waiting for data" windows machine can actually ping 10.6.0.2. What am i doing wrong

Test Sequence:

  UDP Broadcast Client; // Bind Socket Sleep (10); // During this time, the startup Python Program client. WriteData (); // Hello message type  

Qt output:

  To start the UDP socket fixed IP address: "10.6.0.2" successfully bound: QHostAddress (" 10.6.0.2 ") Port: 5678 Now Sending UDP Datagram! Wrote this many bytes: 8 Message: "10.6.0.2" with port number 5678 message: "Hello !!!"  

QT code:

// Constructor UDPBRCaster :: Extra-Broadcaster (QObject * Basic): QObject (parent) {// Init Socket m_UdpSocket = New QUdpSocket (this); // Refer to our IP address to broadcast on QString ipAddress; Forecasting (Constant QHost Address and Address, QN Network Interface :: All Adress ()) {if (address.protocol ()) = QAbstractSocket :: IPv4Protocol & amp; Address! = QHostAddress (QHostAddress :: LocalHost)) (address.toString ()). Includes ("10.")) {IpAddress = address.toString (); QDebug () & lt; & Lt; "Should have fixed IP address:" & lt; & Lt; IP address; break; }} // localhost = mpg = 5678; M_AddressToUse = QHostAddress (IPADress); Bool didBind = m_UdpSocket- & gt; Dam (m_AddressToUse, m_Port); If (! Was done) {qDebug () & lt; & Lt; "Error! It can not be binding on:" & lt; & Lt; M_AddressToUse & lt; & Lt; "Port:" & lt; & Lt; M_Port; } And {qDebug () & lt; & Lt; "Successfully bound:" & lt; & Lt; M_AddressToUse & lt; & Lt; "Port:" & lt; & Lt; M_Port; } // Connect to Ready Red Socket (m_UdpSocket, SIGNAL (readyRead ()), this, slot (readReady ()); } // Write the data socket with zero: Ubabscaster :: Listsdata () {// debug qDebug () & lt; & Lt; "Now the UDP Datagram is being sent!"; // Create a message to send QByteArray messages; Msg.append ("hello !!!"); Qint64 numberOfBytesWritten = m_UdpSocket- & gt; WriteDocument (msg, m_AddressToUse, m_Port); If (numberOfBytesWritten == -1) {qDebug () & lt; & Lt; "Error! Could not write data to socket ..."; } And {qDebug () & lt; & Lt; "It wrote several bytes:" & lt; & Lt; NumberOfBytesWritten; }} // Datagram is available when UdpBroadcaster :: read read () {// QByteArray buffer to get buffer data; Buffer.resize (m_UdpSocket-> pendingDatagramSize ()); QHostAddress sender; Quint 16 ports; M_UdpSocket-> ReadDatagram (buffer.data (), buffer.size (), & sender, & amp; port); QDebug () & lt; & Lt; "Message from:" & lt; & Lt; Sender.toString (); QDebug () & lt; & Lt; "With port number" & lt; & Lt; Harbour; QDebug () & lt; & Lt; "Message:" & lt; & Lt; Buffer; } Python Program:
  import socket import time def main (): UDPiIP = "10.6.0.2" UDPRO = 5678 SOK = socket (Socket) .AF_INET, socket.SOCK_DGRAM) sock.connect (UDP_IP, UDP_PORT)) cnt = 0 while the CNT & lt; 10: print "waiting for data" data, addr = sock.recvfrom (1024) # buffer size 1024 byte print "received message:", time of data. Sleep (1) cnt = cnt + 1 # t our terminal The filename = raw_input () is lost if __name__ == '__main__': main ()  

I had to allow my program through the Windows 7 firewall. Now it works fine.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -