How to transport a file with QTcpSock in LAN?

Reply

Join Date: May 2007
Posts: 32
Reputation: meiyantao is an unknown quantity at this point 
Solved Threads: 0
meiyantao's Avatar
meiyantao meiyantao is offline Offline
Light Poster

How to transport a file with QTcpSock in LAN?

 
0
  #1
Nov 18th, 2007
Hello,everybody!

I'm writing a LAN communication programming,and I need to transport a file between different host computer.
I know that the TCP is a kind of stream-oriented connection.But look at the fallowing codes:
  1. void TripPlanner::sendRequest()
  2. {
  3. QByteArray block;
  4. QDataStream out(&block, QIODevice::WriteOnly);
  5. out.setVersion(QDataStream::Qt_4_1);
  6. out << quint16(0) << quint8('S') << fromComboBox->currentText()
  7. << toComboBox->currentText() << dateEdit->date()
  8. << timeEdit->time();
  9. if (departureRadioButton->isChecked()) {
  10. out << quint8('D');
  11. } else {
  12. out << quint8('A');
  13. }
  14. out.device()->seek(0);
  15. out << quint16(block.size() - sizeof(quint16));
  16. tcpSocket.write(block);
  17. statusLabel->setText(tr("Sending request..."));
  18. }
I don't think it's a stream but a segment,do I?

And my other question is how to transport a file by TcpSocket.
I am Chinese,so the file may not be Enlish single,and the file may be alse a binary data file. How do I transport it?

I know that my English is poor,but I will try my best to exchange it!
Help me,please!
Thank anybody who look at this thread!

By the way, I had another question: what's the meaning of "hen & egg problem"(I'm not a English mother language men).
Last edited by cscgal; Nov 18th, 2007 at 3:34 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 16,601
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1614
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to transport a file with QTcpSock in LAN?

 
0
  #2
Nov 18th, 2007
chicken & egg proglem

If the file contains binary representation of integers then the bytes may have to be reversed on the receiving os. This is common problem when transferring files between MS-Windowos and *nix/Unix -- big endian little endian

As for your specific question -- I don't know, sorry.
Last edited by Ancient Dragon; Nov 18th, 2007 at 3:46 pm.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 32
Reputation: meiyantao is an unknown quantity at this point 
Solved Threads: 0
meiyantao's Avatar
meiyantao meiyantao is offline Offline
Light Poster

Re: How to transport a file with QTcpSock in LAN?

 
0
  #3
Nov 18th, 2007
Originally Posted by Ancient Dragon View Post
chicken & egg proglem
Thanks! Maybe I could find it in google by myself first, I'm sorry for my lazy.

If the file contains binary representation of integers then the bytes may have to be reversed on the receiving os. This is common problem when transferring files between MS-Windowos and *nix/Unix -- big endian little endian
This is important for me. I guess that Qt may encapsulate it in an easy way.
As for your specific question -- I don't know, sorry.
You have help me so much!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 931 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC