开发者

Bandwidth save GPRS and TCP

开发者 https://www.devze.com 2023-02-15 06:07 出处:网络
Hello i have made a program for my old windows mobile phone to send gps data ,temperature etc every 5 seconds just for experimental reasons to create a fleet management system.

Hello i have made a program for my old windows mobile phone to send gps data ,temperature etc every 5 seconds just for experimental reasons to create a fleet management system.

I noticed that within one hour 350kb were consumed although i sent only 20kb of data...

As i dont have deep knowledge in networks ,how much does a tcp connection cost in bytes?

Maybe i should keep the socket alive because i close and open it every 5 seconds.Would that save bytes?

A开发者_JS百科lso does MTU matter here? Any other idea to reduce the overhead? thank you


Let's do some math here.

Every 5 seconds is 720 connections per hour plus data. 20K / 720 is about 28 bytes of payload (your GPS data) for each connection.

IP and TCP headers along are 48 bytes in addition to whatever data is being sent.

3-way handshake connection: 3 packets (2 out, 1 in) == 96 bytes out and 48 bytes in
Outbound Data-packet: 48+28 bytes == 76 bytes (out)
Inbound Ack: 48 bytes (in)
Close: 48 bytes (out)
Final Ack: 48 bytes (in)

Total out per connection: 220
Total in per connection:  144
Total data send/received per connection: 220+144 = 364
Total data usage in one hour = 364 * 720 = 262K

So I'm in the ballpark of your data usage estimates.

If you're looking to reduce bandwidth usage, here's three ideas:

  1. Scale back on your update rate.

  2. Don't tear down the socket connection each time. Just keep it open.

  3. Given your GPS coordinates are periodically updated, you could consider using UDP instead of TCP. There's potential for packet loss, but given you're retransmitting fresher data every 5 seconds anyway, an update getting lost isn't worth the bandwidth to retransmit. IP and UDP headers combined are only 28 bytes with no "connection" overhead.

UPDATE

When I originally posted this, I erroneously misunderstood the connection close to be a single exchange of FIN packets between client and server. In practice, the client sends a FIN as part of it initiating the CLOSE. Then server ACKs the FIN. Then the server sends its own FIN that is ACK'd by the client. In other words, an additional 96 bytes per connection. Redoing our math:

Total data send/received per connection =
220+48 + 144+48 = 460
Total data usage in one hour = 460 * 720 = 331K

So my revised estimate of 331KB in one hour is a bit closer to what the OP saw.

0

精彩评论

暂无评论...
验证码 换一张
取 消