Although HTTP is ubiquitous it comes with its baggage of Headers which in my case is becoming more of a problem. My data to be transferred is an iota of the HTTP header size.
- Is there another protocol that I can use which is still understood by the browsers and other networks and doesn't come with the baggage of HTTP?
- Any other way to skip headers and add it at the destination so only a miniscule of data is transferred over the network?
Many HTTP headers are optional. A typical browser request is much larger than a minimal request, which might look like:
(I can say with confidence that requests of this form work because I use them all the time when testing Web server response via
telnet example.com 80
.)Possibly you can get useful results simply by omitting some headers.
WebSockets are coming in HTML5 and should suit your needs. A standard HTTP connection can be renegotiated to change protocol to websockets. But I suspect the specification might be a bit young, but it might fit the bill.
HTTP requests can be quite small. As chaos points out in his answer, you don't really need to send many headers with a request. The only header that's essential is Host. I can simplify chaos' example a bit more by using HTTP 1.0, which doesn't feature persistent connections.
The reply can be similarly simple
In this case, the overhead of HTTP is about 40 bytes in the request and the response. A standard TCP packet is 1500 bytes so you have plenty of room left over in the response packet for the actual data.
There are other HTTP headers, and they do have value. You can include cache information and do conditional GETs. You can use an HTTP/1.1 persistent socket to make subsequent requests faster. Etc, etc. You don't have to use any of this stuff if you don't want, but one nice thing about HTTP is there's a standard way to do more complicated protocols when you need it.
As for doing minimal HTTP in JavaME, if you really care about every byte you may be best off writing your own simple HTTP client by working with a plain TCP socket. If you're talking to a known server you don't need to implement much at all. (If you're talking to arbitrary servers, you need to pay more attention to error handling, redirects, etc).