Click here to Skip to main content
13,353,706 members (55,348 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 11 Mar 2002

Multithreaded Non-blocking Socket Server and Client, Based on Synchronized Socket

, 11 Mar 2002
Rate this:
Please Sign up or sign in to vote.
Non-blocking socket class using synchronized socket.



Just derive a child CTestClient class from CSyncSocketWorker and override its virtual function ProcessData.

void CTestClient::ProcessData()
     const int nBufferSize = 8192;
    char szBuffer[nBufferSize];

    CFile file;
    file.Open(TEXT("recv.dat"), CFile::modeCreate | CFile::modeWrite);
    int nRead;

    DWORD dwStart = GetTickCount();
    while(nRead = Read(szBuffer, nBufferSize))
        file.Write(szBuffer, nRead);
            cout << "shuting down" << endl;

    cout << "Speed = " << double(file.GetLength()) / 
                  (double(GetTickCount() - dwStart) / 1000.0) / 1024 
         << "KB/s" << endl;


Same as client.

void CEchoWorker::ProcessData()
     const int nBufferSize = 4096;
    char* pBuffer = new char[nBufferSize];

    CFile file;
    file.Open(TEXT("testfile.dat"), CFile::modeRead);
    while(!IsShutingdown() && IsConnected())
        int nRead = file.Read(pBuffer, nBufferSize);
        if(nRead == 0)

        Write(pBuffer, nRead, FALSE);


    while(!IsSendBufferEmpty() && IsConnected())

    delete [] pBuffer;


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Kevin Hua
Web Developer
China China
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralClient data in the Server code Pin
John A. Rose19-Jun-07 19:32
memberJohn A. Rose19-Jun-07 19:32 
Questioncannot reach author. license ? Pin
Petar K. Shomov24-Nov-03 3:52
memberPetar K. Shomov24-Nov-03 3:52 
I tried to reach the author of the code but both e-mail addresses are unreachable(user does not exist).

Anyways, I wanted to ask what is the license for the code. Can anyone use it in non-commercial products ? What about commercial products ?
QuestionUDP? Pin
Amit Dey16-Nov-02 11:51
memberAmit Dey16-Nov-02 11:51 
GeneralBad links have been corrected Pin
Kevin Hua12-Mar-02 16:20
memberKevin Hua12-Mar-02 16:20 
GeneralSorry for broken links Pin
Kevin Hua12-Mar-02 16:00
memberKevin Hua12-Mar-02 16:00 
Generalcan't download! Pin
Anonymous11-Mar-02 20:40
memberAnonymous11-Mar-02 20:40 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 12 Mar 2002
Article Copyright 2002 by Kevin Hua
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid