Read Sockets and Partial Data - Compliance Required

So this is a general question about socket reads.

I am looking for an Objective-C application that someone created that uses the TCP socket library and installs a handler for "didReadData" that takes data and sends it to the JSON parser.

Now ... am I right when I say that this is basically completely wrong? Isn't it that reading sockets can return some, all, or none of the data, depending on many factors, such as network latency? Isn't it that you need to continue reading from the socket until you get to the end of the data - however this is limited - and then parse it? So, for example, for JSON, if you send it over HTTP, do you send a content length header that tells the server (or client) when it can stop reading from the socket? So, if you are not using http and using a raw socket, you will have to have some other separator or mechanism to determine where the message ends.

I am wondering if this particular application was tested only in cases where the client and server are on the same host - so I wonder if the programmer believes that it works, because, by chance, the first reading was always not returned all data.

+3
source share
2 answers

You're right.

The stream is infinite and the message should be marked as such with a delimiter. If the application you are testing relies on a flow object to identify messages without a separator, this will be a problem.

The question is that this functionality is somehow integrated into the socket library. What library are you using?

+2
source

. , , , , .

, Apple NSXMLParser .

(, NSJSONSerialization, , , .)

+1

All Articles