libH/SocketClient.cpp

Go to the documentation of this file.
00001 
00012 /*
00013   
00014   Copyright (c) 2007, Tim Burrell
00015   Licensed under the Apache License, Version 2.0 (the "License");
00016   you may not use this file except in compliance with the License.
00017   You may obtain a copy of the License at 
00018 
00019         http://www.apache.org/licenses/LICENSE-2.0
00020 
00021   Unless required by applicable law or agreed to in writing, software
00022   distributed under the License is distributed on an "AS IS" BASIS,
00023   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00024   See the License for the specific language governing permissions and 
00025   limitations under the License. 
00026   
00027 */
00028 
00029 #include "SocketClient.hpp"
00030 #include "SocketException.hpp"
00031 #include "Debug.hpp"
00032 
00033 using namespace H;
00034 using namespace std;
00035 
00037 // Defines / Type Defs
00039 
00041 // Construction / Deconstruction
00043 
00047 SocketClient::SocketClient() {
00048         mConnected = false;
00049         setEventWatcher(this);
00050 }
00051 
00055 SocketClient::~SocketClient() {
00056 }
00057 
00059 // Class Body
00061 
00067 void SocketClient::connectToServer(std::string Host, int Port) {
00068         createSocket(SOCKET_INTERNET, SOCKET_STREAM);
00069         connect(Host, Port);
00070 }
00071 
00076 bool SocketClient::isClientConnected() {
00077         return mConnected;
00078 }
00079 
00084 void SocketClient::onSocketClientConnect(Socket const & socket) {
00085         // override me
00086         cdbg << "SocketClient :: Socket Connect Detected" << endl;
00087 }
00088 
00093 void SocketClient::onSocketClientDisconnect(Socket const & socket) {
00094         // override me
00095         cdbg << "SocketClient :: Socket Disconnect Detected" << endl;
00096 }
00097 
00103 void SocketClient::onSocketClientMessage(Socket const & socket, std::string const & Message) {
00104         // override me
00105         cdbg << "SocketClient :: Socket Message [" << Message.length() << "] Bytes -- " << Message << endl;
00106 }
00107 
00113 void SocketClient::onSocketClientRead(Socket const & socket, DynamicBuffer<char> & ReadBuffer) {
00114         // override me
00115         cdbg << "SocketClient :: Socket Read [" << ReadBuffer.length() << "] Bytes" << endl;
00116 }
00117 
00124 void SocketClient::onSocketConnect(SocketInterface const & iSocket) {
00125         mConnected = true;
00126         onSocketClientConnect(static_cast<Socket const &>(iSocket));
00127         processEvents();
00128 }
00129 
00136 void SocketClient::onSocketDisconnect(SocketInterface const & iSocket) {
00137         mConnected = false;
00138         onSocketClientDisconnect(static_cast<Socket const &>(iSocket));
00139 }
00140 
00148 void SocketClient::onSocketMessage(SocketInterface const & iSocket, std::string const & Message) {
00149         onSocketClientMessage(static_cast<Socket const &>(iSocket), Message);
00150 }
00151 
00159 void SocketClient::onSocketRead(SocketInterface const & iSocket, DynamicBuffer<char> & ReadBuffer) {
00160         onSocketClientRead(static_cast<Socket const &>(iSocket), ReadBuffer);
00161 }
00162 
00167 void SocketClient::sendToServer(std::string const & Message) {
00168         writeMessage(Message);
00169 }

Generated on Wed Nov 7 10:04:16 2007 for gizmod by  doxygen 1.5.3