ionflux.org | Impressum

TCPClient.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_TCPCLIENT
00002 #define IONFLUX_TOOLS_TCPCLIENT
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * TCPClient.hpp                    Generic TCP client.
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <iostream>
00031 #include <vector>
00032 #include <signal.h>
00033 #include "ionflux/Reporter.hpp"
00034 #include "ionflux/TCPRemotePeer.hpp"
00035 #include "ionflux/IOHandler.hpp"
00036 #include "ionflux/SelectMultiplexer.hpp"
00037 
00038 namespace Ionflux
00039 {
00040 
00041 namespace Tools
00042 {
00043 
00053 class TCPClient
00054 : public IOHandler
00055 {
00056     protected:
00058         Ionflux::Tools::Reporter log;
00060         bool interactive;
00062         std::vector<TCPRemotePeer *> peers;
00064         std::vector<TCPRemotePeer *> trash;
00066         int currentPeerID;
00068         IOMultiplexer *iomp;
00070         bool manageIomp;
00072         IOEvent stdinEvent;
00073         
00080         virtual void addPeer(TCPRemotePeer *peer);
00081         
00088         virtual void removePeer(TCPRemotePeer *peer);
00089         
00094         virtual void cleanupPeers();
00095         
00105         virtual void onConnect(TCPRemotePeer &peer);
00106         
00119         virtual void onReceive(TCPRemotePeer &peer);
00120         
00132         virtual void onDisconnect(TCPRemotePeer &peer);
00133         
00140         virtual void disconnect(TCPRemotePeer *peer);
00141         
00142     public:
00147         TCPClient();
00148         
00156         TCPClient(bool initInteractive);
00157         
00166         TCPClient(bool initInteractive, IOMultiplexer *initIomp);
00167         
00172         virtual ~TCPClient();
00173         
00181         virtual void onInput(const std::string &line);
00182         
00187         virtual void run();
00188         
00194         virtual void cleanup();
00195         
00206         virtual bool addConnection(const std::string &host, int port);
00207         
00214         virtual void broadcast(const std::string &bytes);
00215         
00224         virtual void onIO(const IOEvent &event);
00225         
00232         static void shutdownHandler(int signum);
00233         
00238         virtual Reporter &getLog();
00239 
00240 };
00241 
00242 }
00243 
00244 }
00245 
00249 #endif

Generated on Tue Mar 14 20:58:30 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6