Results 1 to 14 of 14

Thread: QUdpSocket - Send and receive data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QUdpSocket - Send and receive data

    Quote Originally Posted by TheMasterNico View Post
    First problem I see is that you're not sending the exact same data to your server. In your PHP example, you send 11 bytes of data. In your QUdpSocket code, you wind up sending 12 bytes of data, because QChar is a 16-bit unicode type and when you add the QChar for 214, it winds up appending two bytes to your QByteArray instead of one.

    I used the code below and got a response from your server. The Wireshark capture for the exchange is shown below as well.

    Qt Code:
    1. QByteArray Data; // Message for send
    2. Data.append("SAMP");
    3. Data.append(93);
    4. Data.append(119);
    5. Data.append(26);
    6. Data.append(214);
    7. Data.append(7777 & 0xFF);
    8. Data.append(7777 >> 8 & 0xFF);
    9. Data.append('i');
    10. int bytes_written = s.writeDatagram(Data, QHostAddress("93.119.26.214"), 7777);
    To copy to clipboard, switch view to plain text mode 



    No. Time Source Destination Protocol Length Info
    1 0.000000000 172.20.28.17 93.119.26.214 UDP 43 Source port: 7777 Destination port: 7777

    Frame 1: 43 bytes on wire (344 bits), 43 bytes captured (344 bits) on interface 2
    Null/Loopback
    Internet Protocol Version 4, Src: 172.20.28.17 (172.20.28.17), Dst: 93.119.26.214 (93.119.26.214)
    User Datagram Protocol, Src Port: 7777 (7777), Dst Port: 7777 (7777)
    Data (11 bytes)

    0000 53 41 4d 50 5d 77 1a d6 61 1e 69 SAMP]w..a.i
    Data: 53414d505d771ad6611e69
    [Length: 11]

    No. Time Source Destination Protocol Length Info
    2 0.194495000 93.119.26.214 172.20.28.17 UDP 138 Source port: 7777 Destination port: 7777

    Frame 2: 138 bytes on wire (1104 bits), 138 bytes captured (1104 bits) on interface 2
    Null/Loopback
    Internet Protocol Version 4, Src: 93.119.26.214 (93.119.26.214), Dst: 172.20.28.17 (172.20.28.17)
    User Datagram Protocol, Src Port: 7777 (7777), Dst Port: 7777 (7777)
    Data (106 bytes)

    0000 53 41 4d 50 5d 77 1a d6 61 1e 69 00 04 00 94 00 SAMP]w..a.i.....
    0010 32 00 00 00 50 72 6f 66 65 73 73 69 6f 6e 61 6c 2...Professional
    0020 20 52 6f 6c 65 70 6c 61 79 20 7c 20 70 72 6f 2d Roleplay | pro-
    0030 72 6f 6c 65 70 6c 61 79 2e 72 6f 20 5b 30 2e 33 roleplay.ro [0.3
    0040 2e 37 20 52 33 5d 12 00 00 00 52 6f 6c 65 70 6c .7 R3]....Rolepl
    0050 61 79 20 31 39 2e 30 2e 33 2e 37 69 0a 00 00 00 ay 19.0.3.7i....
    0060 4c 6f 73 20 53 61 6e 74 6f 73 Los Santos
    Data: 53414d505d771ad6611e6900040094003200000050726f66.. .
    [Length: 106]


    And the attachment here if you prefer:

    pcap.txt

  2. The following user says thank you to jefftee for this useful post:

    TheMasterNico (16th April 2015)

  3. #2
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QUdpSocket - Send and receive data

    plz send me source it is useful to my application ...

  4. #3
    Join Date
    Apr 2015
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QUdpSocket - Send and receive data

    Quote Originally Posted by mouni View Post
    plz send me source it is useful to my application ...
    Look the previous comments.

Similar Threads

  1. QUdpsocket send and receive broadcast in linux
    By danics in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2015, 11:26
  2. Replies: 1
    Last Post: 13th March 2013, 08:44
  3. QUdpSocket::writeDatagram claims to send but does not
    By oliverg in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2011, 18:00
  4. Replies: 6
    Last Post: 5th February 2011, 20:18
  5. How to send and receive Email ??
    By wincry in forum Newbie
    Replies: 4
    Last Post: 18th October 2009, 17:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.