Re: WSASend()

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Alexander Nickolov (agnickolov_at_mvps.org)
Date: 10/12/04


Date: Tue, 12 Oct 2004 10:23:36 -0700

There's a glaring error in the sample code - the socket is not
created as overlapped, hence no overlapped I/O is happening.
Replace the call to socket() with WSASocket and use the
WSA_FLAG_OVERLAPPED flag. Note the sample is very
inefficient - do not base your real code on it. The reason for
overlapped I/O is so you can service multiple sockets efficiently.
However, the sample code blocks for each send/receive until
completion (and has bugs in its main loop too - does not resume
receiving for example).

-- 
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Martin Wan" <wannabe@hotmail.com> wrote in message 
news:%23HQnvdGsEHA.1232@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I hope this is the correct newsgroup for this kind of question. I'm having 
> some problems with some winsock 2 calls. First I thought I was making 
> something wrong. But then I downloaded a sourcecode sample from Microsofts 
> website and it doesn't seem to work:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsasend_2.asp
>
> The source code under the "Example section" on this page compiles and 
> links just fine, but it doesn't behave as expected. When I run it, I 
> expect it to listen on port 27015, then it should echo back all incoming 
> data to the client until the client disconnects. I have compiled this on 
> several machines with different operating systems and it doesn't work on 
> any of them. I've also had some users test it on their computer and it 
> doesn't work for them either. Have been tested both on Windows XP 
> Professional and Windows 2000 Server.
>
> When connecting to port 27015, the sample software shows an "Client 
> accepted..." on the server side. Then I switch over to the client window. 
> and type A in that window. Than the sample software sends 4000 bytes of 
> unintialzed data to the client.
>
> I added a memset(buffer, 0, DATA_BUFSIZE); directly after the creation of 
> the buffer array which solved the uninitialized data problem. But now the 
> server disconnected the client immediately.
>
> Does anyone here knows if theres a proper working example of WSASend() 
> using overlapped sockets somewhere?
>
> Kind regards,
> MW
> 


Relevant Pages

  • Re: WSASend()
    ... > There's a glaring error in the sample code - the socket is not ... particularly partial to "Network Programming for Microsoft Windows" by Jones ... > overlapped I/O is so you can service multiple sockets efficiently. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Socket Disconnect
    ... the socket the client remains open. ... I used the sample code in .Net's ... socket.Closeinstead of Disconnect. ...
    (microsoft.public.dotnet.general)
  • Re: Client connects to server socket but data is never available
    ... Your accepted socket inherits the properties of your listening ... connection. ... The server works very well as long as it is running BEFORE the client ... But the connection is suspect because even though the overlapped i/o ...
    (microsoft.public.win32.programmer.networks)
  • RE: Server socket problems
    ... This article explains the difference between a socket's overlapped I/O ... When a socket is created, by default it is a blocking socket. ... socket will perform an overlapped I/O operation. ... On Windows NT, you can specify NULL as the ...
    (microsoft.public.win2000.networking)
  • Re: WSARecv call blocking when using overlapped I/O
    ... That's because Win9x doesn't feature overlapped I/O. ... Alexander Nickolov ... >> You need an overlapped socket for overlapped I/O. ... >> Microsoft MVP, MCSD ...
    (microsoft.public.win32.programmer.networks)