bug-commoncpp
[Top][All Lists]
Advanced

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

newbie question: help with writing multithreaded server


From: deshmua
Subject: newbie question: help with writing multithreaded server
Date: Fri, 31 Oct 2003 21:42:00 -0500 (EST)
User-agent: IMP/PHP IMAP webmail program 2.2.7

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




reply via email to

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