views:

355

answers:

5

What is the best way to use sockets on the Windows platform?

Basic sockets I guess, TCP/IP. Maybe for a chat client, or just for learning.

Could someone give me an example of WININET usage?

maybe ftpgetfile()

+2  A: 

That is a very broad question, and depends a lot on your needs.

What level do you need? HTTP/FTP? Or "just sockets" for your own protocol? What kind of performance do you need (amount of connections, expected speed)?

If you choose to go raw API, you should generally stay away from WSAAsyncSelect since performance is abysmal above "a few" concurrent connections. Blocking sockets and thread-per-socket isn't too hot either. WSAEventSelect is slightly tricky, but gets the job done nicely (µtorrent handles a lot of concurrent connections this way). Fancypants really-high-load would be I/O Completion Ports. You could also look into boost ASIO for some portability.

If you want to use standard protocols like HTTP/FTP, check libcurl. Or, for lesser needs and smaller overhead, the standard Windows WININET functions (has a lot of restrictions though).


For using WinINet functions, try starting here - might not be a sample, but at least gives you enough stuff to google for ;)

snemarch
A: 

For basic client server application with TCP/UDP winsock should be sufficient.

Alien01
A: 

Do you mean asynchronous I/O model on windows? There are select, WSAAsyncSelect, WSAEventSelect, Overlapped I/O, I/O Completion Port, also you may want to use Libevent and Boost Asio which are both cross platform.

dragonfly
A: 

WinInet examples you could find in msdn or codeproject.con

Ways to use you could find in nice platofrm independed lib - boost::asio

bb
A: 

If you are looking to use this as a learning experience I would also look at ACE. A C++ cross platform framework that implements a lot of the patterns discussed in Patterns for Concurrent Network and Networked Objects. The author has also written on ACE as well (see here).

Nic Strong