00001
00002 Copyright (c) 2001, Lee Patterson & Ant Works Software
00003 http://ssobjects.sourceforge.net
00004
00005 filename : clientconnector.h
00006 author : Lee Patterson (lee@antws.com)
00007
00008 purpose : A client uses this to connect to a server.
00009 Provides abilty to direct packets via << & >>
00010 operators.
00011 *********************************************************************/
00012
00013 #ifndef CLIENTCONNECTOR_H
00014 #define CLIENTCONNECTOR_H
00015
00016 #include "ssobjects.h"
00017 #include "bufferedsocket.h"
00018
00019 namespace ssobjects
00020 {
00021
00022 #define throwClientConnectorException(m) (throw ClientConnectorException(m,__FILE__,__LINE__))
00023
00028 class ClientConnectorException : public GeneralException
00029 {
00030 public:
00031 ClientConnectorException(char* pchMessage,const char* pFname,const int iLine)
00032 : GeneralException(pchMessage,pFname,iLine){};
00033 };
00034
00043 class ClientConnector
00044 {
00045
00046 #ifdef _WIN32
00047 public:
00048 WSADATA m_wsd;
00049 static bool m_bWSAStarted;
00050 #endif
00051
00052 protected:
00053 unsigned16 m_wPort;
00054 CStr m_strHost;
00055 BufferedSocket* m_pSocket;
00056
00057 protected:
00058 void cleanup();
00059
00060 public:
00061 void handleException(GeneralException& e);
00062 void sendPacket(PacketBuffer* pPkt);
00063 void sendPacket(PacketBuffer& pPkt);
00064 PacketBuffer* recvPacket();
00065 void operator << (PacketBuffer&);
00066 void operator << (PacketBuffer*);
00067 void operator >> (PacketBuffer&);
00068
00069
00070
00071 public:
00072 ClientConnector();
00073 ClientConnector(const char* pszHost,word wPort);
00074 ~ClientConnector();
00075
00076 public:
00077 CONSTCHAR* getServer() {return m_strHost;}
00078 word getPort() {return m_wPort;}
00079 bool isConnected() {return m_pSocket ? true:false;}
00080 BufferedSocket* getSocket();
00081
00082 void reconnect();
00083 void connect();
00084 void connect(const char* szHost,const unsigned wPort);
00085 void close();
00086
00087 private:
00088
00089 ClientConnector(const ClientConnector&);
00090 ClientConnector& operator=(const ClientConnector&);
00091 };
00092
00093 };
00094
00095 #endif //CLIENTCONNECTOR_H