ixo
ixo

Reputation: 559

Networking with C/C++ in a Windows environment

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()

Upvotes: 1

Views: 1917

Answers (5)

snemarch
snemarch

Reputation: 5008

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 ;)

Upvotes: 2

Nic Strong
Nic Strong

Reputation: 6592

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).

Upvotes: 0

bayda
bayda

Reputation: 13581

WinInet examples you could find in msdn or codeproject.con

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

Upvotes: 0

dragonfly
dragonfly

Reputation: 453

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.

Upvotes: 0

anand
anand

Reputation: 11309

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

Upvotes: 0

Related Questions