bug-commoncpp
[Top][All Lists]
Advanced

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

Re: Checking if TCPSession made successful connection


From: Jason . Majors
Subject: Re: Checking if TCPSession made successful connection
Date: Fri, 27 Feb 2004 14:48:31 -0700

> Hello,

> I cannot figure out how to do this right. In the client code below, I've
> made a very simple class extending TCPSession. When called with an
> invalid hostname or port, the Thread is never spawned, it seems.

> So, my question is: how can I check whether the TCPSession failes its
> connection or not? I would like to print "bad hostname", or "connection
> refused on port <port>" appropriately.

TCPSession inherits isActive(), isConnected(), and operator! () from 
Socket. Try those.
http://www.gnu.org/software/commoncpp/docs/refman/html/class_socket.html


> #include <cc++/socket.h>
> #include <iostream>

> using namespace ost;
> using namespace std;

> class mySession : public TCPSession
> {
> public:
> void run() {cout << "Thread running" << endl;}
> void final() {cout << "mySession exiting" << endl;}
> 
> mySession(InetHostAddress host, int port) : TCPSession(host, port)
> { start(); }
> };

> int main(int argc, char **argv)
> {
> const char *host = argv[1];
> const int port = atoi(argv[2]);
> 
> mySession session(host, port);
> Thread::sleep(2000);
> return 0;
> }

> --
> Tor Arvid Lund               ,''`.
> http://totto.homelinux.net  : :' :
> GnuPG key ID: 0xF335ED1E    `. `'
> find it at pgp.mit.edu        `-

> 
> [attachment "signature.asc" deleted by Jason Majors/Scottsdale/Metris] 
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp




reply via email to

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