Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QUDPSocket Help
Qt 6.11 is out! See what's new in the release blog

[SOLVED] QUDPSocket Help

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gundi
    wrote on last edited by
    #1

    All I am trying to learn QUDPSocket and attempting to write an application to push data back and forth across a network between laptops. Nothing fancy just messages, but I want to send a msg from one system and catch it on the other. I found a nice example on line and it works but it seems to write and read the datagrams on the same system. So I have tried to bind the IPs of the two systems and I get nothing. I am sure I am missing something. Here is my code.

    MyUDP::MyUDP(QObject *parent) : QObject(parent)
    {

    socket = new QUdpSocket(this); 
    
    
    socket->connectToHost(QHostAddress(“101.207.29.195”), 1234, QIODevice::ReadWrite); 
    
     connect(socket, SIGNAL), this, SLOT)); 
    

    }

    void MyUDP::WriteData()

    {

    QByteArray data;

    data.append(“Data In”);

    socket->writeDatagram(data, QHostAddress::LocalHost, 1234);

    //this writes and reads fine. 
    

    }

    void MyUDP::WriteData(QByteArray inMessage)

    {

    socket->writeDatagram(inMessage, QHostAddress(“101.207.29.195”), 1234);

    }

    void MyUDP::readyRead()
    {
    QByteArray Buffer;
    Buffer.resize(socket->pendingDatagramSize()); //Pending DatagramSize is size of incoming data
    QHostAddress sender;
    quint16 senderPort;
    socket->readDatagram(Buffer.data(), Buffer.size(), &sender, &senderPort);
    //Process packets here.

    qDebug() << “Message from : “ << sender.toString();

    qDebug() << “Message Port : “ << senderPort;
    qDebug() << “Message : “ << Buffer;
    }

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gundi
      wrote on last edited by
      #2

      Sorry the code is postings strange. I tried to edit it several times.

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
        wrote on last edited by
        #3

        Can you check the network setup ? Can you check whether client box and server box in same network ? Do you have reachability to both boxes ?Are they in same network ?Can you ping each IP address from each box ?
        ie.
        ping 101.207.29.195

        Dheerendra
        @Community Service
        Certified Qt Specialist
        https://www.pthinks.com

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gundi
          wrote on last edited by
          #4

          Yes I have pinged from both machines and they are on the same network. Once is connected through a wireless connection if that makes a difference, but I can still ping it.

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
            wrote on last edited by
            #5

            Difficult to see your code. I can send you the working code. Can you drop email to me ?

            Dheerendra
            @Community Service
            Certified Qt Specialist
            https://www.pthinks.com

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Gundi
              wrote on last edited by
              #6

              No problem what is your email?

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
                wrote on last edited by
                #7

                Just dropped an in mail for you. You can drop me an email.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                https://www.pthinks.com

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Gundi
                  wrote on last edited by
                  #8

                  I sent you a message with my email. Let me know if you received it.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    Gundi
                    wrote on last edited by
                    #9

                    I solved the issue. The server has to be set to LocalHost. then the client connects with the IP address. Everything seems to be listening properly.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      Gundi
                      wrote on last edited by
                      #10

                      I just sent another email

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved