libsocket 1.5
tcpsocket.hh
Go to the documentation of this file.
1/*
2** tcpsocket.hh
3** Login : Julien Lemoine <speedblue@happycoders.org>
4** Started on Sun Mar 2 01:17:01 2003 Julien Lemoine
5** $Id: tcpsocket.hh,v 1.3 2004/06/01 21:30:54 speedblue Exp $
6**
7** Copyright (C) 2003,2004 Julien Lemoine
8** This program is free software; you can redistribute it and/or modify
9** it under the terms of the GNU Lesser General Public License as published by
10** the Free Software Foundation; either version 2 of the License, or
11** (at your option) any later version.
12**
13** This program is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** GNU Lesser General Public License for more details.
17**
18** You should have received a copy of the GNU Lesser General Public License
19** along with this program; if not, write to the Free Software
20** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
23#ifndef TCPSOCKET_HH_
24# define TCPSOCKET_HH_
25
26#include "netsocket.hh"
27
28namespace Network
29{
32 class TcpSocket : public NetSocket
33 {
34 public:
36 NetSocket(TCP, version)
37 {}
39 NetSocket(TCP, pkind, version)
40 {}
41 TcpSocket(int socket, SOCKET_VERSION version = V4) :
42 NetSocket(TCP, version)
43 {
44 _socket = socket;
45 }
46 TcpSocket(int socket, PROTO_KIND pkind, SOCKET_VERSION version = V4) :
47 NetSocket(TCP, pkind, version)
48 {
49 _socket = socket;
50 }
51
52 virtual ~TcpSocket()
53 {
54 close();
55 }
56
57 public:
59
101 void connect(const std::string& hostname, int port);
103 std::string get_ip(TcpSocket *client) const;
104
106 TcpSocket* accept() const;
108
154 void connect(int port);
156 void close();
157
158 protected:
165 std::string _read_line_bin(int socket, int& port,
166 std::string& host, unsigned int psize);
170 std::string _read_line_bin(int socket, unsigned int psize);
171 };
172}
173
174#endif /* !TCPSOCKET_HH_ */
This class represent an abstract socket connection (udp | tcp server | tcp client)
Definition netsocket.hh:34
This class represent a tcp connection (client and server)
Definition tcpsocket.hh:33
TcpSocket(SOCKET_VERSION version=V4)
Definition tcpsocket.hh:35
std::string get_ip(TcpSocket *client) const
return ip of client (after an accept)
Definition tcpsocket.cc:69
void close()
Close the connection.
Definition tcpsocket.cc:74
TcpSocket * accept() const
accept a new client (For server only)
Definition tcpsocket.cc:42
TcpSocket(int socket, SOCKET_VERSION version=V4)
Definition tcpsocket.hh:41
TcpSocket(PROTO_KIND pkind, SOCKET_VERSION version=V4)
Definition tcpsocket.hh:38
TcpSocket(int socket, PROTO_KIND pkind, SOCKET_VERSION version=V4)
Definition tcpsocket.hh:46
void connect(const std::string &hostname, int port)
Connect as an TCP client.
Definition tcpsocket.cc:28
virtual ~TcpSocket()
Definition tcpsocket.hh:52
std::string _read_line_bin(int socket, int &port, std::string &host, unsigned int psize)
Get a line from socket and store client hostname and port in port and host variable (when used with b...
Definition tcpsocket.cc:152
Network namespace represent all networks connection.
@ TCP
Definition socket.hh:80
enum Network::e_version SOCKET_VERSION
enum Network::e_pkind PROTO_KIND