Click here to Skip to main content
15,891,849 members
Articles / High Performance Computing / Parallel Processing

Use of free SocketPro package for creating super client and server applications

Rate me:
Please Sign up or sign in to vote.
4.48/5 (19 votes)
23 Feb 200211 min read 180.4K   6.3K   59  
A set of socket libraries for writing distributed computing applications over the internet
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>Sample tutorial about application of SocketPro for server side development</title>
</head>

<body>

<h3 align="center">Sample tutorial about application of SocketPro for client and server
sides development</h3>

<ol>
  <li>Purpose<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This short article is written for coding
    client-server applications with help of SocketPro package. You are expected to be familiar
    with C++, COM and VB. This sample contains three parts of code, a server socket
    application, an in-process ATL COM component, and a VB test client application.&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </li>
  <li>Analysis of sample scenario<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The sample server socket application
    provides multiple services to multiple clients. These services include: 1) exchange of
    files between client and server, 2) remote management of files, 3) use of server
    proxy/broker on behalf of a client for executing various commands, and 4) host resolving.
    The tutorial provides detailed steps to C++ code for hosting resolving.<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The in-process ATL COM component is a wrapper
    written from a base ATL COM component, ClientSocket.dll, with C++. You can use these
    COM-based components with any languages supporting COM technology.<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The sample VB test application builds upto two
    connections to the sample server socket application. When clicking a button, two sets of
    server names and ip addresses are sent to the sample server application in batch. The two
    connections run asynchronously, independently and in parallel. Whenever a result comes
    from the server, the VB application display it. <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </li>
  <li>Server side coding<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To develop socket server application with
    SocketPro, please take a time to read the short article, <a href="fundamentals.htm"><em>Fundamentals
    about data communication using socket with SocketPro</em></a>. You need to do the
    following work:<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A.&nbsp;&nbsp;&nbsp; Define class and method
    ids, and tell SocketPro what requests are lengthy actions and what requests are quick
    actions, and set up one (at most cases) or more (at extreme cases) structures. See the
    decalarations of the following code at file HostDnsSvs.h, and pay attention to comments.<br>
    <br>
    <font color="#0000FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #define</font>
    &nbsp;&nbsp;&nbsp; HOST_DNS_SVS_SOCKET &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    0xA00100DD
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">&nbsp;&nbsp; //unique</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">#define</font>
    &nbsp;&nbsp;&nbsp; HOST_DNS_SVS_METHOD_ID_GETDNSNAME_BYNAME&nbsp;&nbsp;&nbsp; 1
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">//slow action</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">#define</font>
    &nbsp;&nbsp;&nbsp; HOST_DNS_SVS_METHOD_ID_GETDNSNAME_BYADDR&nbsp;&nbsp;&nbsp; 2
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">//slow action</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">#define</font>
    &nbsp;&nbsp;&nbsp; HOST_DNS_SVS_METHOD_ID_GET_COUNT_CLIENTS&nbsp;&nbsp;&nbsp; 3
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">//slow
    or fast action at run time</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">#define</font>
    &nbsp;&nbsp;&nbsp; HOST_DNS_SVS_METHOD_ID_GET_CLIENTS
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//fast action</font><br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">class</font> CHostDnsSvs
    : public CSockWithThread <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">public:</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    CHostDnsSvs();<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">private:</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008040">//Three lengthy actions invloved</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    SockMethodID &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_pMethodIDs[3];&nbsp;&nbsp;&nbsp;
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    CSockThreadInfo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_pHostThreadInfo[2];<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">protected:</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
    color="#008000">//for processing the request HOST_DNS_SVS_METHOD_ID_GET_CLIENTS <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    //using the main thread/message queue if not many clients are available</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">virtual bool</font> GetClients();<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008040">//for processing the request
    HOST_DNS_SVS_METHOD_ID_GET_COUNT_CLIENTS</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">virtual bool</font> GetCountClients();<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//must be overwrite</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">virtual bool</font> QuickProcess(SockMethodID nMethodID);<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">private:</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//used by two threads/message queues for processing lengthy actions</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    static HRESULT GetHostByNameProc(SOCKET hSocket, SockMethodID nMethodID, void *pBuffer,
    DWORD nBufferLen, void*
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    pSockWithThread);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    static HRESULT GetHostByIPAddrProc(SOCKET hSocket, SockMethodID nMethodID, void *pBuffer,
    DWORD nBufferLen, void*
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    pSockWithThread);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Additionally, see how to set thread/message
    queue structures in the following at the file HostDnsSvs2.cpp:<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CHostDnsSvs::CHostDnsSvs()<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//The class used by the main thread/message queue to dynamically
    create the class objects<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    //once required from a client</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_nClassID=HOST_DNS_SVS_SOCKET;<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//3 lengthy requests will be processed using worker thread/message
    queues</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pMethodIDs[0]=HOST_DNS_SVS_METHOD_ID_GETDNSNAME_BYNAME;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pMethodIDs[1]=HOST_DNS_SVS_METHOD_ID_GET_CLIENTS;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pMethodIDs[2]=HOST_DNS_SVS_METHOD_ID_GETDNSNAME_BYADDR;<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//The first thread/queue uses the function, GetHostByNameProc, <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    //to process two requests, HOST_DNS_SVS_METHOD_ID_GETDNSNAME_BYNAME <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    //and HOST_DNS_SVS_METHOD_ID_GET_CLIENTS</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pHostThreadInfo[0].m_pSlowProcess=GetHostByNameProc;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pHostThreadInfo[0].m_pMethodIDs=m_pMethodIDs;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pHostThreadInfo[0].m_nCountOfMethods=2;<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//The 2nd thread/message queue uses the function
    GetHostByIPAddrProc,<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    //to process one request, HOST_DNS_SVS_METHOD_ID_GETDNSNAME_BYADDR only</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pHostThreadInfo[1].m_pSlowProcess=GetHostByIPAddrProc;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pHostThreadInfo[1].m_nCountOfMethods=1;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pHostThreadInfo[1].m_pMethodIDs=(m_pMethodIDs+2);<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//set the pointer m_pSockThreadInfo to the 2 thread info structues</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_pSockThreadInfo=m_pHostThreadInfo;<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//2 worker thread/message queues will be involved at most</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    m_nCountOfThreadInfos=2; &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; At last, see how to overwrite the function
    QuickProcess. Especially, pay attention to how to differentiate quick and lengthy actions.<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">bool</font>
    CHostDnsSvs::QuickProcess(SockMethodID nMethodID)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">switch</font> (nMethodID)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">case</font> HOST_DNS_SVS_METHOD_ID_GET_COUNT_CLIENTS:<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">return</font> GetCountClients();&nbsp;&nbsp; <font color="#008000">//always
    true</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">break</font>;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">case</font> HOST_DNS_SVS_METHOD_ID_GET_CLIENTS:<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#008000">//true or fase<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    //if true, the request is processed using main thread/queue<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    //if false, it is processed using worker thread/message queue</font><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">return</font> GetClients();&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">break</font>;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">default</font>:<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">break</font>;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    }<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#0000FF">return false</font>;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; B.&nbsp;&nbsp;&nbsp; Code functions to process
    your requests.<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; It is not difficult to finish functions. As you
    can see, your code doesn't deal with any thread/message queue side-effects, data
    synchronization, dead lock and various message routing etc. The complete implementation is
    inside the file HostDnsSvs2.cpp.<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Last finish-up step. See the files
    MultipleStartSvs.h, MultipleStartSvs.cpp, MySocketSvr.h, MySocketSvr.cpp and MainProg.cpp
    (or MultiSvs.h and MultiSvs.cpp from the NT service). You should pay attention to how
    SocketPro can provide multiple services. The secret is the defined class id. For all of
    SocketPro server application, you should use the same pattern code to finish up it with no
    exception.<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
  </li>
  <li>In-process ATL COM component<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This sample shows you how to write a COM object
    wrapper from a base COM object, clientsocket.dll. The complete code and project
    (DResolver) can be found inside the folder sample. Most of codes are associated with COM.
    In regards to code related with host resolving, you need to pay attention to how to handle
    both non-blocking and blocking calls. To determine if a call is blocking one, you need to
    use <em>if((lEvents &amp; FD_READ) != FD_READ)</em>. If a call is non-blocking, you should
    handle returned binary results inside the function call HRESULT __stdcall
    CDNS::OnDataAvailable(long hSocket, long lBytes, long lError).<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </li>
  <li>Sample VB client application<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The VB sample project and code are placed in
    the folder of samples\client\dnssvs\. Look at the code, you will see two socket
    connections are built once clicking the button Connect. Both of the two connections run in
    non-blocking mode. When clicking button Batch calls 1 or button Batch calls 2, you send a
    batch of requests to the above SocketPro Server to process in parallel. The server knows
    how to assign requests onto different threads/message queues. When clicking the button All
    running in parallel, two sets of batch calls are sent to the SocketPro server. In the
    server side, five threads/message queues work togather to process these requests
    concurrently. It is notified that the SocketPro server threads will be killed about 60
    second after all of these requests are processed. Certainly, you can click the button All
    running in parallel again, and send another two sets of batch calls to the SocketPro
    server for processing.<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </li>
  <li>Advantages of the sample clinet-server system<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The system is designed with many advantages.
    Among them, you could see BIG four advantages. They are speed, non-blocking/blocking,
    parallel computation and no worker threads involved with your code at both client and
    server side. In the server side, SocketPro handles all of threads, message queues and
    others for you. The server code can't be simpler, and just can't be simpler! <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </li>
  <li>Notes<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; All of applications included with
    this particular package are free with the following limitations: <ul>
      <li>The NetBaseR.dll enables you to build only two client socket connections to a server
        from a client application. A SocketPro server application only supports accepting 32
        client connections only. </li>
      <li>The file ClientSocket.dll is hard-coded to support 2 socket connections only from one
        client application. </li>
      <li>The client COM dlls, SBroker.dl and DResolver.dll, are totally free to you. </li>
      <li>The client COM dll, SockFile.dll, is free to you except that four functions,
        ISocketFile::GetFile, ISocketFile::SendFile, and ISocketFile::WriteText and
        ISocketFile::WriteChunk, are disabled after 60 days. </li>
      <li>Authentication of both server applications, MultipleSvs.exe and MultiSvs.exe, are
        disabled for your easy setup and testing. You should pay enough attention to security. If
        not, someone may access your server machine files and manage them through the server
        application. <br>
      </li>
    </ul>
    <p>If you need us to do something for you, give us your message using email <a
    href="yekerui@yahoo.com">yekerui@yahoo.com</a>. Service is available now!</p>
  </li>
</ol>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior)
United States United States
Yuancai (Charlie) Ye, an experienced C/C++ software engineer, lives in Atlanta, Georgia. He is an expert at continuous inline request/result batching, real-time stream processing, asynchronous data transferring and parallel computation for the best communication throughput and latency. He has been working at SocketPro (https://github.com/udaparts/socketpro) for more than fifteen years.

Comments and Discussions