Client/Server model

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JohnDenver62
    New Member
    • Apr 2008
    • 1

    Client/Server model

    Hi all,

    I am trying to write a client/server application for TCP or UDP actually at this point the protocol is not important, I am trying to sort out the logic / flow diagram of the problem.

    I will initially configure 50 different physical machines and on each machine there will be three servers running. There will then be one client machine that will communicate with each of these servers. Each server will perform a different a different task and hence has to be kept separated from the others.

    The problem I am having is about the logic of this system.

    The client machine will have to create a connection to each server, (50 *3) so 150 client connections have to be made. Originally I wanted to have two threads per client, one to send data and one to receive data. The reason being that data can be sent without receiving data and vice versa so something like

    Code:
    NetworkStream myData = socket.GetStream();
    while(true)
    {
        //block and wait for read
        myData.read();  
    
        ProcessData();
    
       myData.Send(Response);
    }
    in one thread won't work.

    I was thinking of implementing something more like

    Code:
    ReceiveThread()
    {
      While(true){
        //block and wait for data to arrive
        myData.Receive()
    
        //Use delegates and events to notify data has been received and parsed
        Notify_application_logic_data_received(data)
       }
    }
    
    SendThread()
    {
    
    Array SendBuffer = Empty;
    
       While(true)
       {
          //Block and wait for data to be placed in send buffer
          WaitForNotification();
    
          myData.send(SendBuffer);
       }
    }
    
    Main()
    {
       receivedata += notify(ReadData);
    
       mainSend();
    }
    
    ReadData()
    {
        /whatever has to be done
    }
    
    mainSend()
    {
       //append data to SendBuffer
       //wake up  SendThread to send the data
    }
    The problem is that I will have 300 threads just for communications alone let alone the rest of the application logic. I am afraid that I will spend more time switching threads that actually doing other work.

    I then looked at asynchronous communications and it looks like I will have to constantly poll each connection, to see if data available to read and if the application logic has provided some data to send.

    Has anybody encountered such a problem before. Is 300 threads to much to have ? If each thread is actually blocked until it is woken up either by an event saying data available to read or by me saying here is some data to send so wake up. As you have probably noticed this is C# code on a windows machine.

    Any suggestions will be greatly appreciated.
  • ShahbazAshraf
    New Member
    • Mar 2008
    • 36

    #2
    I think if their is larger number of threads then its good to use different process (i.e. cloning of process) better than creating a huge amount of threads. Their is an ancient war b/w Processes Vs Threads. So in your problem if u think thread switching may be time consuming and windows doesnot handle 300 threads in while, then distribute the application in multiple process.

    Comment

    Working...