source: BAORadio/libindi/libindi/drivers/telescope/ServerSocket.cpp @ 493

Last change on this file since 493 was 493, checked in by frichard, 14 years ago

Le programme gère mieux les connexion/déconnexion des microcontrôleurs.

File size: 1.7 KB
Line 
1// Implementation of the ServerSocket class
2// Franck RICHARD
3// BAORadio
4
5#include "ServerSocket.h"
6#include "SocketException.h"
7#include <net/if.h>
8#include <sys/types.h>
9#include <sys/socket.h>
10#include <sys/ioctl.h>
11#include <netinet/in.h>
12
13
14ServerSocket::ServerSocket ( int port )
15{
16    if ( ! Socket::create() )
17    {
18        throw SocketException ( "Could not create server socket." );
19    }
20
21    if ( ! Socket::bind ( port ) )
22    {
23        throw SocketException ( "Could not bind to port." );
24    }
25
26    if ( ! Socket::listen() )
27    {
28        throw SocketException ( "Could not listen to socket." );
29    }
30
31    Socket::set_non_blocking(true);
32}
33
34ServerSocket::~ServerSocket()
35{
36}
37
38
39const ServerSocket& ServerSocket::operator << ( const std::string& s ) const
40{
41    if ( ! Socket::send ( s ) )
42    {
43        throw SocketException ( "Could not write to socket." );
44    }
45
46    return *this;
47
48}
49
50
51const ServerSocket& ServerSocket::operator >> ( std::string& s ) const
52{
53    if ( ! Socket::recv ( s ) )
54    {
55        throw SocketException ( "Could not read from socket." );
56    }
57
58    return *this;
59}
60
61
62void ServerSocket::accept ( ServerSocket& sock )
63{
64    if ( ! Socket::accept ( sock ) )
65    {
66        throw SocketException ( "Could not accept socket." );
67    }
68}
69
70void ServerSocket::shutdown ( )
71{
72    if ( ! Socket::shutdown (  ) )
73    {
74        throw SocketException ( "Could not shutdown socket." );
75    }
76}
77
78void ServerSocket::create ( )
79{
80    if ( ! Socket::create (  ) )
81    {
82        throw SocketException ( "Could not create socket." );
83    }
84}
85
86bool ServerSocket::connect(std::string IP ) 
87{
88   return Socket::connect (IP, 8000); 
89}
90
91std::string ServerSocket::recupip( ServerSocket& sock)
92{ 
93   return ( Socket::recupip() ); 
94}
Note: See TracBrowser for help on using the repository browser.