Re: WSASend()
From: Alexander Nickolov (agnickolov_at_mvps.org)
Date: 10/12/04
- Next message: Alun Jones [MSFT]: "Re: WSASend()"
- Previous message: John: "IO Completion ports and closesocket()"
- In reply to: Martin Wan: "WSASend()"
- Next in thread: Alun Jones [MSFT]: "Re: WSASend()"
- Reply: Alun Jones [MSFT]: "Re: WSASend()"
- Messages sorted by: [ date ] [ thread ]
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 >
- Next message: Alun Jones [MSFT]: "Re: WSASend()"
- Previous message: John: "IO Completion ports and closesocket()"
- In reply to: Martin Wan: "WSASend()"
- Next in thread: Alun Jones [MSFT]: "Re: WSASend()"
- Reply: Alun Jones [MSFT]: "Re: WSASend()"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|