sockets vs http

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
agravayne
Forum Newbie
Posts: 8
Joined: Thu Dec 04, 2008 4:55 am

sockets vs http

Post by agravayne »

Hello,

Not sure if this is the correct place to post this as it kind of fits everywhere! lol

Anyway, we are designing a new piece of hardware that will send messages to our server. The question I have is whether we send the messages vie http to a PHP page or use sockets - possibly having a php listening socket. I am trying to find information on which way is the best way to go - all I can find are some sockets tutorials but these don't really answer the question as to which is best.

The problem we are anticipating the the volume - the messages are very small 9 bytes on average but there will eventually be many of them. They cold grow to 6000 a minute. We don't want to put a strain on the web server by receiving all these messages and at the same time serving web pages to the clients. Also we are being charged a network charge for bandwidth.

My thinking that the packages sent on Http would be larger due to the header information? But has anyone got any idea how much larger? Can anyone think of any dire reasons not to go with a socket approach?

We are running a LAMP server on Cent OS.

Many thanks
Scott Bailey
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: sockets vs http

Post by Weirdan »

agravayne wrote:My thinking that the packages sent on Http would be larger due to the header information?

Correct.
agravayne wrote:But has anyone got any idea how much larger?
Here I will assume you're opening new connection for every message you send. If it's not the case (i.e. you may send multiple messages per session) you will need to adjust this calculations accordingly.

Theoretically it depends on MTU of a network, over which you're connecting to the server. Normally there will be 3 packets sent to establish a connection (counting in both directions), 1 packet sent to server containing the request data, 1 packet sent from server to acknowledge it has received the data and 4 packets sent (counting in both directions) to close the connection. TCP has a header size of 20 (or 24, if there are Options field specified) bytes, IPv4 adds another 20 (or 24) bytes. Thus any successful TCP/IP session has a minimum traffic of 320 bytes. Application level protocols add their overhead on top of that. HTTP adds another roundtrip from server to client (server sends a response and client has to ack it), plus actual protocol overhead. Minimal HTTP request would look like this:

Code: Select all

 
GET / HTTP/0.9\r\f\r\f
 
and minimal (successful) HTTP response - like this:

Code: Select all

 
HTTP/0.9 200 OK\r\f\r\f
 
where \r stands for carriage return and \f stands for line feed characters. Thus minimal HTTP session would produce 3*40 + 40+18 + 40+19 + 40 + 4*40 = 437 bytes of traffic.
agravayne wrote:Can anyone think of any dire reasons not to go with a socket approach?
If message loss is acceptable, I'd suggest using UDP, which has much lower overhead. TCP connection has a significant overhead on itself, regardless of whether you use HTTP or not.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: sockets vs http

Post by Darhazer »

Usually we are dealing with HTTP 1.1 and minimal request will add Host: header to this :)

My opinion: if there is no reason not to use sockets, that just use sockets. Implementing custom protocols of course have disadvantages, especially if the protocol should be open for third-party developers
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: sockets vs http

Post by Weirdan »

Darhazer wrote:Usually we are dealing with HTTP 1.1 and minimal request will add Host: header to this :)
And I forgot Ethernet frame header + frame crc, which adds another 18 bytes (in case of DIX frames) to every packet.
Post Reply