开发者

Sequence of packets 'waitForBytesWritten' of QIODevice

Are these codes the same behaviour for the remote:

a:

 socket.write("aaaa");
 socket.waitForBytesWrite(3000);
 socket.writ开发者_C百科e("b");

b:

 socket.write("aaaa");
 socket.write("b");

I know the first code will get "aaaab" but.. I don't know if the second codes would result in "aabaa" or something else.


They are equivalent (as in, the remote end should receive the same order of data). In your second case if the socket has not finished sending it's current chunk of data, the new data to send will be appended to the end of the internal buffer for later writing.

This assumes, of course, that you're using TCP - if you use UDP, there's no guarantees the packets will arrive in the order you send them.


What type of socket are you using? TCP or UDP?

If you use TCP socket:

First and second lines will result in "aaaab".


If you are using UDP:

First and second lines in a very bad condition will result in "aaaab" or "baaaa". Below code is better to insure the sequence of UDP packets

socket.write("aaaa");
if (socket.waitForBytesWrite(3000))
   socket.write("b");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜