CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2007
    Posts
    44

    Single Server Multiple Clients

    hi,

    i am doing a big windows programming project. In the initialization state the program should connect to a server and asks for permission to start. Asking for permission is made by sending and receiving data(floating license). For example:

    Program starts.
    Connect to server.
    Send a message to server ("hello")
    Receive a message from server ("hello")
    Send a message to server ("can i run?")
    Receive a message from server ("yea") // these are done automatically in every start.

    In the network each computer that runs my product show connect to server and send receive message. The problem is:

    When i implement simple socket programming it does not provide multiple clients. I need a server/client application that supports multiple clients.

    I am not good at socket programming and i have to work more on the rest of the project; so, i am looking an implementation, lib, class ...etc. to do what i want easily. (this is an mfc project/server can be console application).

    thanks for help

  2. #2
    Join Date
    Jun 2007
    Posts
    9

    Re: Single Server Multiple Clients

    use ACE

  3. #3
    Join Date
    May 2006
    Location
    Indonesia & Japan
    Posts
    399

    Re: Single Server Multiple Clients

    You can use multithreading technique to handle connected socket.
    By passing accepted socket to new thread, you still can handle
    listening socket. The other way is using multi process (using fork()
    function).

  4. #4
    Join Date
    Jul 2007
    Posts
    213

    Re: Single Server Multiple Clients

    if i do what henky said, then if "nthread" is the new thread that handle a connection from a client, do the nthread have all function like socket, i mean if i can do that for example ?

    Code:
    nthread.send(xxxxxxxx);
    tnx

  5. #5
    Join Date
    Apr 2007
    Posts
    90

    Re: Single Server Multiple Clients

    You might one to consider the IO completion port of Winsock strategy, it's the most efficient IO strategy that I have seen so far, it can receive many clients connection and perform IO operations concurrently. This link will be good for you to start http://www.codeproject.com/internet/SimpleIOCPApp.asp
    Last edited by keenlearner; July 27th, 2007 at 04:17 PM.

  6. #6
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Single Server Multiple Clients

    The OP is writing a client, whereas the article you gave him is for a server.

    Incidentally, the article provides a file named clientIOCP.zip, and describes the file as follows:
    ClientIOCP.zip contains the IOCP client; the IOCP client can stress-test the IOCP server.
    It sounds like a client using IOCP, but in fact the code most decidedly does not use IOCP. Rather, it is a simple multi-threaded client using standard BSD socket calls.

    Mike

  7. #7
    Join Date
    Apr 2007
    Posts
    90

    Re: Single Server Multiple Clients

    Quote Originally Posted by hkullana
    I need a server/client application that supports multiple clients.
    He needs to support multiple clients, so I assume that he like to built the server application. Even if it's a client application, after reading the link and understand how IOCP work, we will be able to apply ourselves for client as well.

    Hello, MikeAThon, since you said that it does not applied IOCP on the client, what will be the benefit of IOCP on client, is it one client able to connect to multiple server ? It will be interesting if you would tell me what other benefits, because most IOCP code that I saw always deal with the server. Thank you.

    PS : I just tried to help as maximum with as maximum knowledge that I have learnt so far, sorry if I am wrong.
    Last edited by keenlearner; July 28th, 2007 at 02:37 AM.

  8. #8
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Single Server Multiple Clients

    As you yourself learned here, "WSAAsyncSelect with IOCP for client ", http://www.codeguru.com/forum/showthread.php?t=427541 , reliance on that article alone will not teach you how to use IOCP for a client. You also need to know about the ConnectEx() function.

    As for advantages in a client, IOCP in a client provides the same advantages as in a server, namely, highly efficient processing for a large number of simultaneous connections. The reason that you do not find sample code for a client is that the client rarely needs those advantages, whereas most servers do. There are only a few cases where the client needs those advantages, and one is the web scaping robot that you and the OP are building, which explains why it's rare to find any IOCP code for a client.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured