0

My project was standalone application then I decided to split it as client & server because I need powerful CPU usage and portability at the same time. Now multiple clients can connect to one server.

It was easy when 1 by 1 processing did the job. Now I need to call the same function & scope area again & again at the same time -via client requests-

Please can anyone give me some clue how should I handle these operations, I need to know how can I isolate clients' processes from each other at the server side? My communication is asynchronous, server receives a request and starts a new thread. I think I pass a parameter which one carries the client information, and another parameter as job id -to help client back, client may ask for multiple jobs and some jobs finish quicker than others-

Should I instantiate the class Process on each call? Can I use a static method, etc, any explanation will be of great help!

Below is the part of my code to need modification

class static readonly Data
{
    public variable listOfValues[]
}


class Process
{

    local variable bestValue



    function findBestValue(from, to)
    {
    ...
     if(processResult > bestValue) bestValue = processResult
    ...

    }

    ...

    for(i=0;i<10;i++) startThread(findBestValue(i*1000,i*1000+999));
...
}

EDIT: I think I have to instantiate a new Process class and call the function for each client and ignore the same client for same job since job is already running.

2 Answers 2

2

Not getting into your application design, since you didn't talk much about it, I think that your problem is ideal for using WCF WebServices. You get client isolation by design because every request will start in it's own thread. You can create WCF host as standalone application/windows service.

1
  • I think it's late a little bit, I just invented the wheel, I used tcp-ip & XML and succeed. In version 2.0, I will think about WCF but I have to find a solution at the moment.
    – Nime Cloud
    Mar 24, 2011 at 13:43
2

You can wrap your communication with WCF service and configure it to be PerCall service (meaning each request will be processed separately from others).

So you'll clean up your buisness logic from syncronization stuff. That's the best way, because managing and creating threads is not difficult to implement, but it is difficult to implement correctly and optimized for resources consumption.

2
  • I have no WCP experience & I've already done communication sub-processes. I need to call a function in parallel threads.
    – Nime Cloud
    Mar 24, 2011 at 13:46
  • it's as simple as to take a candy. Just add new public WCF service into your server side and then add reference to client side. It is much simpler then using TCP & XML, believe me. You'll need 30 minutes to make it work, not more. Mar 24, 2011 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.