libsocket 1.5
|
00001 /* 00002 ** tcpsocket.hh 00003 ** Login : Julien Lemoine <speedblue@happycoders.org> 00004 ** Started on Sun Mar 2 01:17:01 2003 Julien Lemoine 00005 ** $Id: tcpsocket.hh,v 1.3 2004/06/01 21:30:54 speedblue Exp $ 00006 ** 00007 ** Copyright (C) 2003,2004 Julien Lemoine 00008 ** This program is free software; you can redistribute it and/or modify 00009 ** it under the terms of the GNU Lesser General Public License as published by 00010 ** the Free Software Foundation; either version 2 of the License, or 00011 ** (at your option) any later version. 00012 ** 00013 ** This program is distributed in the hope that it will be useful, 00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 ** GNU Lesser General Public License for more details. 00017 ** 00018 ** You should have received a copy of the GNU Lesser General Public License 00019 ** along with this program; if not, write to the Free Software 00020 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef TCPSOCKET_HH_ 00024 # define TCPSOCKET_HH_ 00025 00026 #include "netsocket.hh" 00027 00028 namespace Network 00029 { 00032 class TcpSocket : public NetSocket 00033 { 00034 public: 00035 TcpSocket(SOCKET_VERSION version = V4) : 00036 NetSocket(TCP, version) 00037 {} 00038 TcpSocket(PROTO_KIND pkind, SOCKET_VERSION version = V4) : 00039 NetSocket(TCP, pkind, version) 00040 {} 00041 TcpSocket(int socket, SOCKET_VERSION version = V4) : 00042 NetSocket(TCP, version) 00043 { 00044 _socket = socket; 00045 } 00046 TcpSocket(int socket, PROTO_KIND pkind, SOCKET_VERSION version = V4) : 00047 NetSocket(TCP, pkind, version) 00048 { 00049 _socket = socket; 00050 } 00051 00052 virtual ~TcpSocket() 00053 { 00054 close(); 00055 } 00056 00057 public: 00059 00101 void connect(const std::string& hostname, int port); 00103 std::string get_ip(TcpSocket *client) const; 00104 00106 TcpSocket* accept() const; 00108 00154 void connect(int port); 00156 void close(); 00157 00158 protected: 00165 std::string _read_line_bin(int socket, int& port, 00166 std::string& host, unsigned int psize); 00170 std::string _read_line_bin(int socket, unsigned int psize); 00171 }; 00172 } 00173 00174 #endif /* !TCPSOCKET_HH_ */