1

I Need to send files using HTTP protocols, but the question is should I use sockets because I have big files ? or I can use WinHttpApi such as :

BOOL HttpSendRequest(
  __in  HINTERNET hRequest,
  __in  LPCTSTR lpszHeaders,
  __in  DWORD dwHeadersLength,
  __in  LPVOID lpOptional,
  __in  DWORD dwOptionalLength
);

and use the lpOptional for the file I want ? and should I devide the file or this API handles big files?

Is there any limitation in files size if I used the HTTP apis and should I devide data?

CnativeFreak
  • 712
  • 12
  • 27
  • 1
    What do you think HTTP uses to send the file? :-) – ziesemer Jan 14 '12 at 19:50
  • @ziesemer I know it uses sockets ..but in sockets u need to silce the packet into MTUs, and my question is do we need to do this when dealing with HTTP apis or they already took this overhead into their implementation – CnativeFreak Jan 14 '12 at 19:56

2 Answers2

2

HTTP uses TCP sockets for its connection:

HTTP communication usually takes place over TCP/IP connections. The default port is TCP 80 [19], but other ports can be used. This does not preclude HTTP from being implemented on top of any other protocol on the Internet, or on other networks. [...]

(It could in principle use something else, but that would be quite unusual.)

The advantage of using an HTTP over designing your own protocol over a socket is that there are plenty of existing HTTP libraries (amongst other arguments). You would have to define your own little protocol anyway, if only to tell the remote party when the file starts and stops.

A few points that HTTP helps with:

If you do choose to use HTTP, try to read a bit more about it though. You may actually find that web servers and web clients already implement what you need. I'm not sure what lpOptional is about, but you should specify the file you want to get in the URL you construct. (Build your own URL space on your server.)

Community
  • 1
  • 1
Bruno
  • 119,590
  • 31
  • 270
  • 376
  • The thing is i will be using HTTP to upload to the server from the client... my question was just to know if I need to care about making packets equal to MTUs or HTTP apis provided by Microsoft does that on behalf ...theoretically they must have implemented that .. – CnativeFreak Jan 14 '12 at 20:24
  • HTTP will take care of that. In fact, even for plain TCP sockets, the OS should take care of the MTU segmentation (it's mostly a concern for UDP sockets as far as I know). – Bruno Jan 14 '12 at 20:27
  • You may need to split some data into buffers to read/write from a TCP socket under Linux, but this isn't related to MTU as far as I know. Any pointers regarding your MTU concern? See: http://stackoverflow.com/a/2407459/372643 – Bruno Jan 14 '12 at 20:32
1

HTTP is just a higher layer protocol on top of sockets. So any issue that you'll have with sockets will be faced with HTTP as well.

How large are the files you're thinking of? Pretty much any limitations won't be due to your choice of API, but constraints such as bandwidth.

ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • In sockets I remember that we need to slice the data into pieces smaller than the maximum transmission unit, but since microsoft implemented HTTP protocol and gave API to it ..I am just wondering if they implemented this (since ofcaurse they will be using their sockets API) – CnativeFreak Jan 14 '12 at 19:54
  • @CnativeFreak - only if you're using the lowest level APIs to sockets - which again, the HTTP API will have to be doing behind the scenes as well. – ziesemer Jan 14 '12 at 19:57