Jump to content
  • Advertisement
Sign in to follow this  
gretty

Which Win32 method is best to upload a file to a server

This topic is 2611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I have a WinAPI C++ application & I need to upload a file to my server. I want to use native WinAPI libraries/header files to upload the file so that my application will work on windows platforms 2000 & up & because I want to learn how to do it in win32 which I think will be fun. This means that I dont want to use a 3rd party library but learn how to do it the native WinAPI way.

Which of the following "Libraries"/Methods would be best for my needs?
- WinHTTP
- WinSock
- WinINet

Maybe there are better WinAPI libraries that I haven't mentioned aswell?

The method of uploading I would use is either TCP, HTTP or UDP but I am not sure which transfer protocol would be best for what I am doing? Which would you suggest?

Share this post


Link to post
Share on other sites
Advertisement
Few points:

  • TCP and UDP are transport protocols. They exist to enable higher-level forms of communication. You don't want to use them directly.
  • HTTP is a content protocol. It exists to support moving data around, but its upload features are not the best, and security can be problematic.
  • FTP is probably the protocol you want if you have an existing server.
  • Winsock is a low-level library; you use it to speak a content protocol directly on top of TCP or UDP. You probably don't want to start with this.
  • WinInet is a superset of WinHTTP. You probably would want to prefer WinInet over WinHTTP, and definitely if you want FTP support, as detailed here.
  • That said, WinHTTP is newer, a bit cleaner, and a bit more secure, so if you go with HTTP, you should use it.
  • None of this has anything to do with Win32, except for doing it by hand in Winsock. You still are using a third party library.

    If you want to get the job done, just use libcurl and be done. If you're actually out for a learning exercise and a huge amount of unnecessary work, using Winsock directly is pretty much your only way to avoid "library dependencies."

Share this post


Link to post
Share on other sites

Hello

I have a WinAPI C++ application & I need to upload a file to my server. I want to use native WinAPI libraries/header files to upload the file so that my application will work on windows platforms 2000 & up & because I want to learn how to do it in win32 which I think will be fun. This means that I dont want to use a 3rd party library but learn how to do it the native WinAPI way.

Which of the following "Libraries"/Methods would be best for my needs?
- WinHTTP
- WinSock
- WinINet

Maybe there are better WinAPI libraries that I haven't mentioned aswell?

The method of uploading I would use is either TCP, HTTP or UDP but I am not sure which transfer protocol would be best for what I am doing? Which would you suggest?




The native API way is winsock. I like to program raw API too. Just be careful with one thing. If your files are big you will have to send it in chunks. Use send() to send 8K in each call.
But even breaking it in chunks, send() may not be able to send all 8K because the network may not be fast enough. So be prepared for send() to fail and retry again.
If you have problems better ask in the networking forum.

Share this post


Link to post
Share on other sites
The only problem I have with libcurl is that there is a dependency on it being installed on the user's machine. If you're distributing it with your program, then fine, but otherwise you need to be aware of this.

Share this post


Link to post
Share on other sites
Yeah, but how often do you really write software with truly no external dependencies? It's harder than it sounds :-)

Share this post


Link to post
Share on other sites

The only problem I have with libcurl is that there is a dependency on it being installed on the user's machine. If you're distributing it with your program, then fine, but otherwise you need to be aware of this.


If that really bothers you then with it being a MIT licence based library you could just statically compile it into your app...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!