ra170
ra170

Reputation: 3683

Looking for a simplest (and fastest) example of TCP socket programming for windows, c or c++

I'm looking for a simplest (and fastest) example of TCP socket programming for windows, c or c++, whichever can get it accomplished faster, sending trival data, for example 1 byte, or several bytes, but in one packet. It's for research purposes. I googled and found several examples, however every single of out them looks a bit different, some are in C, some are in C++, some use ZeroMemory (from windows), some use memset, some of them assign data in different ways, so while I can find examples of winsock in c/c++ and while I'm not an expert in socket programming - I'm not sure what's the absolutely minimalistic c/c++ code to get it accomplish in a fastest way possible.

I know that UDP would be much faster, but it needs to be reliable at the same time, hence I'm looking for TCP.

I guess I could try each of them and try to time them, but was wondering if some socket/winsock expert here would have a super simple server/client in C/C++ with some timing function (high resolution) at the end. I say super simple, because I'm trying to determine how fast (and the fastest way) can socket transmit on my machines, of course it can include turning off Nagle's algorithm, which is what I would like to do anyway. I'm not sure what other tricks people use.

Thanks.

Upvotes: 4

Views: 10510

Answers (8)

Billy ONeal
Billy ONeal

Reputation: 106609

The most minimal examples of which I am aware are in Beej's Guide.

Upvotes: 1

Jorge Ramirez
Jorge Ramirez

Reputation: 91

ucspi-tcp

Oldie but goodie, written in C, qmail is widely used mail server is based on it.

https://cr.yp.to/ucspi-tcp.html

Upvotes: 0

charfeddine.ahmed
charfeddine.ahmed

Reputation: 546

You can check Push Framework.

Upvotes: 0

Nim
Nim

Reputation: 33645

If you want an off the shelf product, look at any of the messaging products available. They require the least amount of coding to get going, typical examples are:

Open Source:

  1. OpenDDS - based on the DDS protocol (very high performance - used in things like submarine, ship control systems etc.) Their implementation is slightly slower than raw boost::asio, however for ease of use and the bells and whistles, hard to beat.
  2. ZeroMQ - similar to DDS, but based on the MQ protocol, again very fast (millions of messages/sec), MQ is established, but ZeroMQ is not there yet.
  3. AMQP - I believe you'll be able to find something from Red Hat in this space, again very fast, and a new protocol.

Commercial:

  1. Tibco RV: hard to beat, except by hardware vendors
  2. 29West - hardware (and software - thought I've never personally played with it)
  3. Solace - hardware
  4. Tervella - hardware

The last three assumes you've got a few million bucks lying around! ;)

Upvotes: 1

Peter G.
Peter G.

Reputation: 15144

Before writing the third comment, I collect them in an answer

Upvotes: 0

mmr
mmr

Reputation: 14929

I've just implemented a network solution using socket++, and it works pretty well. I believe that it's the basis for boost asio, so if you don't want to install all of boost, you can check it out.

The point of the library is that you can use a stream with your socket, sending data as you would to std::cout or std::cerr.

EDIT: if you're using more recent versions of windows, then this library would need some tweaking to compile (it works fine as-is for XP, but apparently some networking code got moved around for win vista and 7).

Upvotes: 0

Kyle C
Kyle C

Reputation: 1637

Boost Asio is probably your best bet. it's a very good library with timing support and everything you should need to get going.

edit: I know that this isn't a pre-built client/server which is exactly what you are looking for, but Asio makes it extremely easy to get what you want out of a few lines of code.

Upvotes: 1

Steve Townsend
Steve Townsend

Reputation: 54178

Try Len Holgate's socket server framework. I believe he has commercialized this in a packaged version but this should be a good place to start. There is a client implementation tutorial included. This is not the simplest code but if you are interested in maximizing performance, simple code may not meet your needs.

You will have to add your own timing support, but that's likely true for any possible off-the-shelf package.

Upvotes: 2

Related Questions