Click here to Skip to main content
15,901,505 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt31-Jan-12 6:43
professionalJochen Arndt31-Jan-12 6:43 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer0131-Jan-12 6:58
SledgeHammer0131-Jan-12 6:58 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt31-Jan-12 7:14
professionalJochen Arndt31-Jan-12 7:14 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer0131-Jan-12 7:19
SledgeHammer0131-Jan-12 7:19 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer0131-Jan-12 14:12
SledgeHammer0131-Jan-12 14:12 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt31-Jan-12 21:25
professionalJochen Arndt31-Jan-12 21:25 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer011-Feb-12 6:52
SledgeHammer011-Feb-12 6:52 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt1-Feb-12 7:35
professionalJochen Arndt1-Feb-12 7:35 
Try my code without using GetQueuedCompletionStatus() and waiting for data using WaitForMultipleObjects(). The code has been copied from an existing application.

I have never used GetQueuedCompletionStatus(), because blocking functions may cause problems. E.g. your shut down event will be only processed after the blocking function returns. If the network connection of the system drops, this will never occur.

To test your code, you should check the return value of GetQueuedCompletionStatus(), and test if bytes has been read (dwBytesTransferred).

You should also test your code with only one thread first to ensure that problems are not sourced by using multiple threads. In your code you are starting 8 receives in a loop where each uses the same variables. I'm not sure if that is working.

Another point:
C++
int nBytesRecv = -1;
nBytesRecv = WSARecvFrom(pClientContext->GetSocket(), pWSABUF, 1, &dwBytesTransferred, &dwFlags, (sockaddr*)&from, &nFromLen, pOverlapped, NULL);
int j = WSAGetLastError();

WSARecvFrom() does not return the number of bytes reads. It returns 0 upon success. Upon success you should not call GetLastError() because it returns the most recent error which may be from any previous called function that fails. Alternatively, you can call SetLastError(0) before executing a function that may set an error value.
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer011-Feb-12 7:53
SledgeHammer011-Feb-12 7:53 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt1-Feb-12 8:00
professionalJochen Arndt1-Feb-12 8:00 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer011-Feb-12 8:09
SledgeHammer011-Feb-12 8:09 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer011-Feb-12 8:19
SledgeHammer011-Feb-12 8:19 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer011-Feb-12 8:31
SledgeHammer011-Feb-12 8:31 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer011-Feb-12 11:10
SledgeHammer011-Feb-12 11:10 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt1-Feb-12 21:04
professionalJochen Arndt1-Feb-12 21:04 
QuestionLINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 Pin
KASR130-Jan-12 4:01
KASR130-Jan-12 4:01 
AnswerRe: LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 Pin
Chris Losinger30-Jan-12 4:37
professionalChris Losinger30-Jan-12 4:37 
GeneralRe: LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 Pin
KASR130-Jan-12 5:46
KASR130-Jan-12 5:46 
GeneralRe: LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 Pin
Chris Losinger30-Jan-12 5:51
professionalChris Losinger30-Jan-12 5:51 
GeneralRe: LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 Pin
KASR130-Jan-12 6:42
KASR130-Jan-12 6:42 
QuestionRe: LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 Pin
David Crow30-Jan-12 5:13
David Crow30-Jan-12 5:13 
GeneralRe: LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 Pin
KASR130-Jan-12 5:28
KASR130-Jan-12 5:28 
AnswerRe: LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 Pin
Stephen Hewitt31-Jan-12 3:22
Stephen Hewitt31-Jan-12 3:22 
QuestionHow to call load a dialog of an activeX control in a mfc application Pin
Adity Bhattacharya30-Jan-12 1:14
Adity Bhattacharya30-Jan-12 1:14 
AnswerRe: How to call load a dialog of an activeX control in a mfc application Pin
«_Superman_»30-Jan-12 16:09
professional«_Superman_»30-Jan-12 16:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.