bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Bug-commoncpp Digest, Vol 12, Issue 1


From: Julie Russell
Subject: RE: Bug-commoncpp Digest, Vol 12, Issue 1
Date: Mon, 03 Nov 2003 10:49:08 +1100

Hi there!

I am not a big expert on this package, but the code in this thread package
is very similar to Java. You would do something like this:

class MultipleServices {
private:
        MyThread *service_1;
        MyThread *service_2;
public:
        MultipleServices();

};

#include "MultipleServices.h"
MultipleServices::MultipleServices() {
        this->service_1 = new MyThread(server_port_1);
        this->service_2 = new MyThread(server_port_2);
        this->service_1->start();
        this->service_2->start();
        // or if you want to start the thread off as detached
        //this->service_1->detach();
        //this->service_2->detach();
}



class MyThread : public Thread {
private:
        ServerSocket* serverSocket;
public:
        // MyThread's run method is describe briefly below:
        void run();
};

#include "MyThread.h"
void MyThread::run() {
        serverSocket = new ServerSocket(port);
        while (true) {
                sock = serverSocket->suspend(); // block till someone connects
                sock->resume(); // resume thread??

                // not sure what you are doing here as I do not know the java 
thread
libraries that
                // well but I assume you are trying to suspend a thread and 
resume it when
some event happens?
                // anyway if that's the case you use suspend() and resume(), or 
you
setSuspend(...) depending on
                // what you are trying to do...
        }
}

Hope this helps...
Regards,
Julie.


> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden
> Behalf Of address@hidden
> Sent: Sunday, 2 November 2003 7:03 AM
> To: address@hidden
> Subject: Bug-commoncpp Digest, Vol 12, Issue 1
>
>
> *This message was transferred with a trial version of CommuniGate(tm) Pro*
> Send Bug-commoncpp mailing list submissions to
>       address@hidden
>
> To subscribe or unsubscribe via the World Wide Web, visit
>       http://mail.gnu.org/mailman/listinfo/bug-commoncpp
> or, via email, send a message with subject or body 'help' to
>       address@hidden
>
> You can reach the person managing the list at
>       address@hidden
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Bug-commoncpp digest..."
>
>
> Today's Topics:
>
>    1. newbie question: help with writing multithreaded server
>       (address@hidden)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 31 Oct 2003 21:42:00 -0500 (EST)
> From: address@hidden
> Subject: newbie question: help with writing multithreaded server
> To: address@hidden
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
> ** sorry for posting a newbie question here, if there is a
> separate list for
> such questions, please let it be known ***
>
> I just started using GNU Common C++. I have a problem understanding
> the class organization of this package. I'm trying to create
> a class that starts off multiple TCP servers (each in a separate thread).
> Is there something analogous to the Java ServerSocket class that creates
> and listens on a socket to accept connections (which may be eventually
> services in a separate thread)
>
> I come from Java background, so I find it difficult to understand why
> such a simple task seems to be so complicated with this library.
> Ideally I am looking for something like:
>
> --------------------snip code---------------------
> // in the class "MultipleServices"
> class MultipleServices {
> MyThread *service_1;
> MyThread *service_2;
> .
> .
> .
> // in constructor or some method...
> *service_1 = new MyThread(server_port_1);
> *service_2 = new MyThread(server_port_2);
> service_1->start();
> service_2->start();
> .
> .
> .
> }; // class MultipleServices ends.
>
>
>
> class MyThread : public Thread {
> .
> .
> .
> // MyThread's run method is describe briefly below:
> void run() {
>     serverSocket = new ServerSocket(port);
>     while (true) {
>         sock = serverSocket->accept(); // block till someone connects
>         service(sock); // this may or may not start in its on thread
>     }
> }
> }; // class MyThread ends
> --------------------snip code---------------------
>
> Can anyone write the same code in a concise way using the "GNU Common C++"
> library. I'm particularly confused since I cannot understand GNU
> Common C++
> analogy to ServerSocket class in Java.
>
> TIA,
> ~ amol
>
>
>
> ------------------------------
>
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp
>
>
> End of Bug-commoncpp Digest, Vol 12, Issue 1
> ********************************************
>
>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]