views:

51

answers:

3

I have two phones connected to a Wifi access point, both have ip in the private range. One of the phones has a HTTP server running on it and the other phone acts like a client. The client sends GET requests data to the server as name/ value pairs in the URL query string. At the moment the server is only sending on HTTP.OK on receiving the query string.

What is happening is the client may not be stationary and maybe moving around so it may not be possible for it to be in range always of the Wifi access point due to that I am not getting all the data sent from the client at the server end. I want to ensure that all data sent is actually received by the server.

What kind of error correction should I implement? Can I check for some relevant HTTP error codes or the like?

+1  A: 

You need to check for timeouts on the client. That depends on the process/language used.

EDIT: http://wiki.forum.nokia.com/index.php/Using_Http_and_Https_in_Java_ME

Looks like you simply set a timeout and catch IO errors.

SpliFF
And how do I do that? I have written the app in JavaME
Kevin Boyd
i don't do java, you'll have to check the documentation for your HTTP request object. Presumably an error will be thrown and you'll need to catch it or else some type of status code will be returned.
SpliFF
+1  A: 

If the HTTP server doesn't receive the entire query string in a GET request, then the HTTP request cannot possibly be valid as these parameters are on the first line of the request.

The server will be unable to handle the request and in this case will likely return status code 400 (Bad Request).

If your client receives this (which seems unlikely that it would fail to transmit the request, yet receive the response), then you'll know to retransmit. In general, the properties of TCP connections like automatic retransmissions, checksums and timeouts should be all you need for successful delivery, or to determine failure.

Christopher
it's highly unlikely any server would respond to a request that excluded the end-of-headers (2 CRLFs). Your only response is going to be no response (ie, a timeout).
SpliFF
Hmm. `echo "GET / HTTP/1.0" | nc httpd.apache.org 80` (or microsoft.com) gives me a 400 error straight away.
Christopher
@ Christopher: That means if I get a 400 code back that would be considered that the server got a faulty or malformed query string right? What if the server is down will I still get a 400.
Kevin Boyd
Yes, that's right. If the server is down or the connection is interrupted, your HTTP client would most likely throw an appropriate IO exception.
Christopher
+1  A: 

Premature optimization.

Connection integrity is already dealt with in the lower parts of the network stack. So if there were any dropouts in the middle of the request (assuming it spanned more than a single packet) the TCP stack would attempt to recover them before passing the data on to the server.

If you need to prove this to yourself, then just add a checksum as the last part of the query.

C.

symcbean
using a short keep alive and timeout on the client socket would be a good idea though.
symcbean