bug-commoncpp
[Top][All Lists]
Advanced

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

TCPSession(&TCPSocket) should duplicate the "server socket" right?


From: Robert Kling
Subject: TCPSession(&TCPSocket) should duplicate the "server socket" right?
Date: 31 Jul 2003 15:49:18 +0200

Hi

I realize that this probably isnt a bug but Im getting desperate.

Im trying to implement a server that listens on a derived TCPSocket and
when a connection occurs a TCPSession with that socket is created.
Something like this:

    fetchTCPSession *tcpsession;

    InetHostAddress localaddr;
    localaddr = htonl(INADDR_ANY);

    try
    {
        cpTCPSocket server(localaddr, GCD_FETCH_PORT);

        while(server.isPendingConnection(30000))
        {
                tcpsession = new fetchTCPSession(server);
                tcpsession->detach();
        }
    }
    CATCH_SOCKET_EXCEPTION("ClientProviderThread::run");

Now, this always generates a "socket error" (the CATCH_EXCEPTION
thingy). The onAccept function in cpTCPSocket looks like this:

bool cpTCPSocket::onAccept(const InetHostAddress &ia, tpport_t port)
{
        cout << "** ClientProviderThread: accepting fetch from " <<
        ia.getHostname() << ":" << port << endl;
        return true;
}

This runs fine. Also the fetchTCPSession is created and run

fetchTCPSession::fetchTCPSession(TCPSocket &server) : TCPSession(server)
{
        tpport_t localport;
        InetHostAddress local = getLocal(&localport);
        printf("** ClientProviderThread: on %s:%d\n",
        local.getHostname(), localport);
}

but after this the "socket error" from the main isPending-loop occurs.

>From what I know from server-client software, shouldn't the
server-socket first accept the connection (in the main thread), and then
a TCPSession be instanciated (automatically a new thread) and the first
thing that happens (automatically by TCPSession?) is that the server
socket is duplicated? Because the port in the TCPSession is the same as
for the "main server socket" and this is no good, that port should only
be for acception new connections. 

Sorry for the rant, but im getting annnooooyeed.. >:-/

Very grateful for replies
/Robert





reply via email to

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