netsocket.hh
Go to the documentation of this file.
/*
** netsocket.hh
** Login : Julien Lemoine <speedblue@happycoders.org>
** Started on Mon May 12 22:23:32 2003 Julien Lemoine
** $Id: netsocket.hh,v 1.2 2004/06/01 21:30:53 speedblue Exp $
**
** Copyright (C) 2003,2004 Julien Lemoine
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef NETSOCKET_HH_
# define NETSOCKET_HH_
#include "socket.hh"
namespace Network
{
class NetSocket : public Socket
{
public:
NetSocket(SOCKET_KIND kind, SOCKET_VERSION version = V4) :
Socket(kind, version), _port(0)
{
}
NetSocket(SOCKET_KIND kind, PROTO_KIND pkind, SOCKET_VERSION version = V4) :
Socket(kind, pkind, version), _port(0)
{
}
virtual ~NetSocket() {}
public:
virtual void writeto(const std::string& str,
const std::string& host, int port);
std::string read();
std::string read(int timeout);
std::string read(int& port, std::string& host);
std::string read(int& port, std::string& host, int timeout);
std::string readn(unsigned int size);
std::string readn(int timeout, unsigned int size);
std::string readn(int& port, std::string& host, unsigned int size);
std::string readn(int& port, std::string& host, int timeout,
unsigned int size);
protected:
struct sockaddr_in _get_addr(int port) const;
#ifdef IPV6_ENABLED
struct sockaddr_in6 _get_addr6(int port) const;
#endif
struct sockaddr_in _get_addr(const std::string& host,
int port) const;
#ifdef IPV6_ENABLED
struct sockaddr_in6 _get_addr6(const std::string& host,
int port) const;
#endif
int _bind(int port, const std::string& host);
int _bind(int port);
int _accept(int port, int server_socket) const;
std::string _get_ip(int port, int socket) const;
void _connect(int socket, int port,
const std::string& host) const;
std::string _read_line(int socket);
std::string _read_line(int socket, int& port,
std::string& host);
virtual std::string _read_line_bin(int socket, int& port,
std::string& host,
unsigned int pkg_size) = 0;
virtual std::string _read_line_bin(int socket, unsigned int size) = 0;
void _write_str(int socket, const std::string& str,
const std::string& host, int port) const;
void _write_str_bin(int socket, const std::string& str,
const std::string& host, int port) const;
protected:
int _port;
};
}
#endif /* !NETSOCKET_HH_ */
Network::NetSocket::readn
std::string readn(unsigned int size)
read a string from socket
Definition: netsocket.cc:575
socket.hh
Network::NetSocket::_accept
int _accept(int port, int server_socket) const
Wait for a client.
Definition: netsocket.cc:211
Network::NetSocket::NetSocket
NetSocket(SOCKET_KIND kind, SOCKET_VERSION version=V4)
Definition: netsocket.hh:36
Network::NetSocket::read
std::string read()
function used by >> operator (read a string on current socket)
Definition: netsocket.cc:533
Network
Network namespace represent all networks connection.
Definition: localsocket.cc:32
Network::NetSocket
This class represent an abstract socket connection (udp | tcp server | tcp client)
Definition: netsocket.hh:33
Network::NetSocket::_port
int _port
Definition: netsocket.hh:161
Network::NetSocket::writeto
virtual void writeto(const std::string &str, const std::string &host, int port)
function used to send a msg to a specific host (UDP)
Definition: netsocket.cc:502
Network::PROTO_KIND
enum Network::e_pkind PROTO_KIND
Network::NetSocket::~NetSocket
virtual ~NetSocket()
Definition: netsocket.hh:45
Network::V4
@ V4
Definition: socket.hh:87
Network::SOCKET_VERSION
enum Network::e_version SOCKET_VERSION
Network::NetSocket::_connect
void _connect(int socket, int port, const std::string &host) const
Connect to a hostname.
Definition: netsocket.cc:186
Network::NetSocket::_write_str_bin
void _write_str_bin(int socket, const std::string &str, const std::string &host, int port) const
Write a string to a socket to a particular host (UDP) (when used with binary protocol)
Definition: netsocket.cc:446
Network::NetSocket::_bind
int _bind(int port, const std::string &host)
Bind a UDP server.
Definition: netsocket.cc:86
Network::Socket
This class represent an abstract socket connection (udp | tcp server | tcp client)
Definition: socket.hh:100
Network::NetSocket::_read_line
std::string _read_line(int socket)
Get a line from socket (when used with textual protocol)
Definition: netsocket.cc:261
Network::NetSocket::_write_str
void _write_str(int socket, const std::string &str, const std::string &host, int port) const
Write a string to a socket to a particular host (UDP) (when used with textual protocol)
Definition: netsocket.cc:400
Network::NetSocket::_get_ip
std::string _get_ip(int port, int socket) const
Get Client Ip.
Definition: netsocket.cc:243
Network::NetSocket::NetSocket
NetSocket(SOCKET_KIND kind, PROTO_KIND pkind, SOCKET_VERSION version=V4)
Definition: netsocket.hh:40
Network::NetSocket::_get_addr
struct sockaddr_in _get_addr(int port) const
internal function (construct a sockaddr)
Definition: netsocket.cc:61
Network::SOCKET_KIND
enum Network::e_kind SOCKET_KIND
Network::NetSocket::_read_line_bin
virtual std::string _read_line_bin(int socket, int &port, std::string &host, unsigned int pkg_size)=0
Get a line from socket and store client hostname and port in port and host variable (when used with b...