For example there is a
tcpsocket
while (10> i)
{
tcpsocket.write ( one package )
+ + i;
}
I do not know how to write data version
seeking to bail Jia
There has server and client systems im qt of it? Find examples of very anxious
------ Solution -------------------------------- ------------
large amount of data you do ? Use waitForBytesWritten do some waiting
------ Solution ----------------------------------- ---------
first look is not your data has not sent out on the end of the program
look at the receiving end is not your only receive data once
------ Solution ------------------------ --------------------
This requires the definition of communication protocols. Explicitly tell each other how your data is considered fat finished.
There are two common ways :
1. the data you want to send the forefront plus two or four bytes in length mark. When receiving peer must be received at least these bytes to arrive at an accurate length of the transmitted data. Then you have been waiting , waiting for all of the data received . Might inspire a few times during the readyRead. This method is suitable for binary data transmission .
2. use XML, the specific reference QXmlStreamReader, when you send a complete XML format data , the last line must be EndDocument, you can use this to determine the data have been received . This method is more suitable for text data sent
------ eference -------------------------------- -------
enters the event loop it?
------ eference --------------------------------------- < br>
ask what is the event loop ? ?
I write when the first packet can be sent to the following package unable to go
qt examples are pitch-catch never seen a continuous contract does not know what the problem is find good people to solve Jia
------ eference ---------------------------------------
Some students may not understand what I mean
when using QTcpSocket
such as continuous write
socket.write (" Data 1 " )
socket.write (" Data 2" )
socket.write (" Data 3" )
socket.write (" Data 4" )
At this time , the data 2,3,4 unable to 99.99 % Data do not know why ?
------ eference --------------------------------------- < br> waitForBytesWritten I tried was unable to
------ eference ------------------------ ---------------
data has been hindered in the transmit buffer it? This problem may not be sent , but the question of the end of the reception
------ eference -------------------------- -------------
guess you write a function parameter in question , write to confirm parameter contains all the data
------ eference ------- --------------------------------
I have confirmed that there is no problem over data parameters
commented one can send 2
commented 2 can be made 3
. . . . .
------ eference ------------------------------------ ---
receiving end of my signal response onreadyread
when debugging on the server if I write in four places are parked about a minute and then re- send the client sends a signal four onreadyread
This instructions are received.
but the server run directly , the client receives only a onreadyread debug signals . The other three did not write it.
------ eference --------------------------------------- < br> readyRead not know the client calls a few write, it is responsible for the data reaches the trigger , and so when you actually receive, might have been able to receive all the data. It depends on the amount of information you send , and if a few words , once readyRead can read all the data ! But remember , this is not inevitable !
------ eference --------------------------------------- < br> so how should I do to send and receive data
How do I know how much data needs to be read
For example, I write (1024 bytes )
write (1024 bytes )
If only one onreadyread signal is issued , how do I know that the second data has been sent
how I should change the way contract and received the package ?
seeking answers to the big cow ? Thank ah
------ eference ------------------------------------ ---
So how should I do to send and receive data
How do I know how much data needs to be read
For example, I write (1024 bytes )
write (1024 bytes )
If only one onreadyread signal is issued , how do I know that the second data has been sent
how I should change the way contract and received the package ?
seeking answers to the big cow ? Thank ah
------ eference -------------------------------------- -
thank you for your help , especially xiachm. Now more aware of this problem.
------ eference --------------------------------------- < br>
Thanks for sharing such a good experience xiachm !
------ eference --------------------------------------- < br> rookie learn, the more I have the similar problem.
没有评论:
发表评论