hii
Qt Code:
struct Stcp { int a; float b; char [50]; } Stcp sendTcp;To copy to clipboard, switch view to plain text mode
I want to send whole sendTcp from server to client.
Pls help...
hii
Qt Code:
struct Stcp { int a; float b; char [50]; } Stcp sendTcp;To copy to clipboard, switch view to plain text mode
I want to send whole sendTcp from server to client.
Pls help...
Last edited by jpn; 18th December 2008 at 14:09. Reason: missing [code] tags
Do you *know* that the client is "binary" compatible with the server?
If not, you might have to convert the int from little to big endian...
If that is not an issue:
(You don't need to send the size of that packet, as the size is fix.)Qt Code:
// assuming your socket is called socketTo copy to clipboard, switch view to plain text mode
If that is an issue:
construct a QDataStream on the socket, and stream all the members out.
Prefix the packet by the packet size, so the client has a chance to know when the complete packet has been received.
The network-fortuneserver examples shows, how to add the package's size to the package.
The network-fortuneclient shows how to wait til the complete package has been received.
HTH
If both sides are Qt, it might be also worth implementing QDataStream stream operators. See Qt Centre Wiki: [WIKI]Using custom data types with Qt[/WIKI] for more details.
J-P Nurmi
hii caduel
i'm getting folowing error :
error: no matching function for call to `QByteArray::fromRawData
(sendTcp*, unsigned int)'
Pls help.
You have to cast that pointer to const char*, then it should work.
(Note that jpn is right: if both sides are written by you, then the little work of supporting QDataStream is probably a good idea.)
Bookmarks