Olivier
Olivier

Reputation: 18

Which is the best protocol to send the smallest data to a server

I have to make real time communication between a webapp (on mobile devices) and a server, so how to send only an integer with HTML, or Javascript ? I've seen websockets, but is there an other protocol or an other way to send data with no header informations ?

Thanks

Upvotes: 0

Views: 208

Answers (2)

Farrukh Subhani
Farrukh Subhani

Reputation: 2038

Use JSON.

I would like to know what kind of device you are using where you are thinking of avoiding headers. Even The network providing 3G or WIFI is not without some kind of meta and device information so adding headers is not an overhead to your mobile device for real time communication.

Sending 1 bit or a byte to server will have the same latency as sending upto 1KB of segment. Please read section 4.2 of RFC 3481 for 2.5G and 3G supported mobile devices. You can check relevant RFC for window size and initial overhead of your device and network to make sure you use correct amount of data.

To give you an example if you have a bucket to hold 5 ltr of water and you go 10Km to fetch it. If you have to fetch 5.5 ltr water you have to make 2 journeys. Its upto you how you load balance. Doing 10 journeys to bring 55 ltr is not right but doing 2 journeys to bring 5.5 is unavoidable.

Upvotes: 1

MSalters
MSalters

Reputation: 179991

There's little benefit to sending less than a full TCP/IP packet; don't overdo the optimizations. Even a simple

POST /recv.jsp HTTP/1.1
Host: x.example.nl
User-Agent: <>
Content-Length: 7
Content-Type: application/x-www-form-urlencoded

value=8

probably fits in a single TCP/IP packet. Note: use a domain without cookies for this.

Upvotes: 1

Related Questions