ws2_32 socket send seems to hang

Greetings,
I'm writing a DLL (in C) to communicate with a "target" application via TCP. Essentially the DLL implements three functions: Connect, WriteRead, and Close. A "client" app will use the DLL to control the target app. The client will call Connect once, call WriteRead many times, then call Close.

The WriteRead function calls socket send. It's supposed to call socket recv after send, but recv is commented-out for now.

What I'm observing is that the socket "send" does not send until after the WriteRead function-call terminates. I put Sleep(5000) after send, and the call to WriteRead "hangs" for 5sec, then the sent data shows-up at the target.

Please help me understand why/how "send" appears to hang until the DLL WriteRead function-call terminates.

Thanks!

Is the server reading? Does it receive anything?
Hi/Thanks kbw,
The server is polling(reading) the connection at about 4Hz and sees nothing until the (post-send) 5-sec sleep expires (function-call terminates), then the server gets the whole message (about 30 bytes).

Note that send is completing without error!
It seems the data is buffered somewhere on the client and doesn't "escape" until after the function-call terminates.
The server is polling(reading) the connection at about 4Hz
I'm not quite sure I understand how you're doing that, or whether you should.

Normally, you'd call poll() or select() with a timeout. The function would block until something interesting happened or the time expired. You wouldn't run a game loop with network code.

It seems the data is buffered somewhere on the client and doesn't "escape" until after the function-call terminates.
I'm not sure which function you mean. Do you mean your WriteRead() thing?
kbw:
"Problem" solved.
The DLL call was simply blocking, preventing the TCP Read logic from executing. Normally this would not be possible, because client and server will be separate Windows apps; however, I was running both the client and server in their source-code forms within a LabVIEW IDE.

Last edited on
Topic archived. No new replies allowed.