Results 1 to 4 of 4

Thread: Sending and Receiving an integer array through TCP connection

  1. #1
    Join Date
    Mar 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Sending and Receiving an integer array through TCP connection

    Hey,

    I was wondering if anyone could help me with this, I am able to write a string and receive the string but I would like it to be an integer array instead. I am using QTcpSocket to create the connection between the client and server.

    The following is the coding I am using for sending the string over
    Qt Code:
    1. client.write("hello", 5);
    To copy to clipboard, switch view to plain text mode 

    And the following is the code I am using for receiving the string
    Qt Code:
    1. char buffer [1024] = {0};
    2. client.read(buffer, client.byteAvailable());
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Strateng

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: Sending and Receiving an integer array through TCP connection

    Use QDataStream to implement a real protocol. Have a look at the Fortune Client example.

  3. #3
    Join Date
    Mar 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Sending and Receiving an integer array through TCP connection

    Hey,

    Oh okay. I was looking through that but I was also wondering would it be possible to use QTcpSocket and QNetwork to connect to another program using TCP connection that is written in C++ but not with QT sending the integer array? And if so, would you be able to provide an example coding of it?

    Thanks,
    Strateng

    Quote Originally Posted by spud View Post
    Use QDataStream to implement a real protocol. Have a look at the Fortune Client example.

  4. #4
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: Sending and Receiving an integer array through TCP connection

    You can access the data like this if both systems have the same endianess.
    Qt Code:
    1. int* data = reinterpret_cast<int*>(buffer);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 2nd April 2010, 06:42
  2. QUdpSocket: sending and receiving on the same socket?
    By mhoover in forum Qt Programming
    Replies: 16
    Last Post: 17th June 2009, 03:28
  3. integer as a QTableWidgetItem ?
    By tommy in forum Qt Programming
    Replies: 7
    Last Post: 29th May 2009, 17:44
  4. sending int array through socket
    By babu198649 in forum Qt Programming
    Replies: 5
    Last Post: 20th December 2007, 08:16
  5. Converting to integer
    By Salazaar in forum Newbie
    Replies: 2
    Last Post: 15th June 2007, 20:11

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.