views:

636

answers:

2

Hi everyone,

I hope you can help me out.

I'm trying to send packets of 1000 bits across a network via TCP/IP and I was hoping to be able to use the Overlapped I/O technique in both Cygwin and Windows as well.

In Cygwin, I am trying to use the "readv() and writev()" function calls to send 1000 bits across while in Windows, I am trying to use the WSASend() and WSARecv() APIs in the winsock2.h header file.

It seems that I can ONLY send 1000 bits from Cygwin(client.cpp) to Windows(server.cpp). More than 1000 bits, and I encounter unexpected results. It seems as though the bits get wrapped around or overwritten.

I've search all over the internet but it seems that no one has ever tried using this approach to things as I did and thus I am seeking your help in this, please.

Thank you and best regards, Cornelius

A: 

Your question is quite unclear, you need to clarify it. Here are some ideas, still:

  • Sending "packets" using TCP is not a good idea. TCP's data model is a byte stream.
  • Are you sure you mean 1000 bits, and not 1000 bytes?
  • You need to clarify what you mean by "unexpected results", it is very vague.
  • Overlapped I/O seems to be a Windows-specific technique for asynchronous I/O, I would not expect that to work in Cygwin.
unwind
+1  A: 

If you want to use overlapped I/O on windows then you might like to take a look at some articles I wrote over at The Code Project which might provide you with a starting point. These use IO Completion Ports which are the most efficient way of doing overlapped I/O on Windows and come with complete source code. There's a link to the articles and the latest source here.

From your brief problem description it's hard to tell exactly what might be going wrong. It's most likely that you are assuming that your reads will read the same amount of data that you are writing and this just isn't the case with TCP; TCP is a stream of bytes and your reads need to take that into account and loop accordingly until you have reassembled a complete 'message'.

Len Holgate