ios - How to know whether this is the last packet sent from a bulletin board system -
i writing bulletin board scheme (bbs) reader on ios. utilize gcdasyncsocket library handle packets sending , receiving. issue have server splits info send multiple packets. can see happens printing out receiving string in didreceivedata() function.
from gcdasyncsocket readme, understand tcp stream. know there end of stream mechanisms, such double cr lfs @ end. have used wireshark parse packets, there no sign of sort of pattern in lastly info packet. site not owned me, couldn't create send bytes. there must way observe lastly packet, otherwise how bulletin board system clients handle displaying data?
double cr lfs not end of stream. part of details of http protocol, example, has nil closing stream. http 1.1 allows me send multiple responses on single stream, double cr lf after http header, without end of stream.
the tcp socket stream homecoming 0 on read when closed other end, blocking or non-blocking.
so assuming server close socket when done sending you, can loop , perform blocking read , if returns > 0, process data, read again. if < 0, process error code (could fatal or not), , if == 0, socket closed other side, don't read again.
for non-blocking sockets, can utilize select() or other api observe when stream becomes ready read. i'm not familiar specific lib using if posix / berkeley sockets api, work way.
in either case, should build buffer of input, concatenating results of each read until ready process. you've found, can't assume single read homecoming finish application level packet. question, unless server wants close socket, should wait read homecoming 0.
ios sockets tcp network-protocols gcdasyncsocket
No comments:
Post a Comment