Click here to Skip to main content
15,925,602 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionmay i read the same object on network from a file? Pin
imran_rafique26-Sep-02 16:03
imran_rafique26-Sep-02 16:03 
AnswerRe: may i read the same object on network from a file? Pin
jmkhael26-Sep-02 22:00
jmkhael26-Sep-02 22:00 
GeneralWSAAsyncSelect I/O & Multithreading :: Winsock Pin
valikac26-Sep-02 13:23
valikac26-Sep-02 13:23 
GeneralRe: WSAAsyncSelect I/O & Multithreading :: Winsock Pin
jmkhael26-Sep-02 22:02
jmkhael26-Sep-02 22:02 
GeneralRe: WSAAsyncSelect I/O & Multithreading :: Winsock Pin
valikac26-Sep-02 22:33
valikac26-Sep-02 22:33 
GeneralRe: WSAAsyncSelect I/O & Multithreading :: Winsock Pin
Jon Hulatt26-Sep-02 22:44
Jon Hulatt26-Sep-02 22:44 
GeneralRe: WSAAsyncSelect I/O & Multithreading :: Winsock Pin
jmkhael26-Sep-02 22:46
jmkhael26-Sep-02 22:46 
GeneralRe: WSAAsyncSelect I/O & Multithreading :: Winsock Pin
Jon Hulatt26-Sep-02 22:50
Jon Hulatt26-Sep-02 22:50 
I think your best way of implementing this is to make new threads for each client connection.

Then, within the read thread, you can have a loop similar to this, which consumes negligible CPU time:-

WSAEVENT event;
WSANETWORKEVENTS netevents;

event = WSACreateEvent();
WSAEventSelect(s, event, FD_READ | FD_CLOSE);

DWORD result, lIdleTimeout;
lIdleTimeout=0


while (TRUE)
{
    result = WSAWaitForMultipleEvents(1, &event, FALSE, 100, FALSE);

    if (result == WSA_WAIT_TIMEOUT)
    {
        if (++lIdleTimeout > IDLE_CONNECTION_TIMEOUT)
        {
            // close this idle connection
            closesocket(s);
            return FALSE;
        }
        continue;
    }

    lIdleTimeout=0;

    WSAEnumNetworkEvents(s, event, &netevents);

    if (netevents.lNetworkEvents & FD_CLOSE) {
        // handle socket closure
        printf ("socket closed\n");
        return TRUE;
    }

    if (netevents.lNetworkEvents & FD_READ) {
        // handle a read

        continue;
    }
}


The key here is that WSAWaitForMultipleEvents() is very very lightweight. This example was for a connection thread for a server type socket, but implementing a similar theory in a client socket is simple.

Signature space for rent. Apply by email to....
GeneralRe: WSAAsyncSelect I/O & Multithreading :: Winsock Pin
valikac27-Sep-02 5:14
valikac27-Sep-02 5:14 
GeneralDialog message question Pin
Anonymous26-Sep-02 11:33
Anonymous26-Sep-02 11:33 
GeneralRe: Dialog message question Pin
Shog926-Sep-02 12:06
sitebuilderShog926-Sep-02 12:06 
GeneralThe WM_SET_TEXT message Pin
Fiffismurf26-Sep-02 11:21
Fiffismurf26-Sep-02 11:21 
GeneralRe: The WM_SET_TEXT message Pin
RedZenBird26-Sep-02 11:23
RedZenBird26-Sep-02 11:23 
GeneralRe: The WM_SET_TEXT message Pin
Fiffismurf26-Sep-02 11:35
Fiffismurf26-Sep-02 11:35 
GeneralRe: The WM_SET_TEXT message Pin
Jon Hulatt26-Sep-02 22:54
Jon Hulatt26-Sep-02 22:54 
GeneralRe: The WM_SET_TEXT message Pin
Steve S27-Sep-02 0:30
Steve S27-Sep-02 0:30 
GeneralRe: The WM_SET_TEXT message Pin
Shog926-Sep-02 11:56
sitebuilderShog926-Sep-02 11:56 
GeneralRe: The WM_SET_TEXT message Pin
Fiffismurf27-Sep-02 7:13
Fiffismurf27-Sep-02 7:13 
QuestionCannot change transfer var? Pin
jimNLX26-Sep-02 11:07
jimNLX26-Sep-02 11:07 
AnswerRe: Cannot change transfer var? Pin
Gary R. Wheeler29-Sep-02 5:53
Gary R. Wheeler29-Sep-02 5:53 
QuestionIs there a limit on amt of timers in an app? Pin
JohnnyG26-Sep-02 11:06
JohnnyG26-Sep-02 11:06 
AnswerRe: Is there a limit on amt of timers in an app? Pin
RedZenBird26-Sep-02 11:18
RedZenBird26-Sep-02 11:18 
GeneralRe: Is there a limit on amt of timers in an app? Pin
JohnnyG27-Sep-02 3:17
JohnnyG27-Sep-02 3:17 
GeneralRe: Is there a limit on amt of timers in an app? Pin
RedZenBird27-Sep-02 6:52
RedZenBird27-Sep-02 6:52 
GeneralRe: Is there a limit on amt of timers in an app? Pin
JohnnyG27-Sep-02 9:11
JohnnyG27-Sep-02 9:11 

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.