source: BAORadio/libindi/v1.0.1/BAOControl/ClientSocket.cpp@ 654

Last change on this file since 654 was 502, checked in by frichard, 15 years ago

-BAOControl : petite interface permettant de contrôler les antennes via le pilote indi_BAO
-Le pilote indi_BAO utilise désormais indilib v 0.7

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1// Implementation of the ClientSocket class
2
3#include "ClientSocket.h"
4#include "SocketException.h"
5
6
7#include <iostream>
8#include <string>
9#include <string.h>
10#include <stdio.h>
11#include <stdlib.h>
12
13
14ClientSocket::ClientSocket ( std::string host, int port )
15{
16 if ( ! Socket::create() )
17 {
18 throw SocketException ( "Could not create client socket." );
19 }
20
21 if ( ! Socket::connect ( host, port ) )
22 {
23 throw SocketException ( "Could not bind to port." );
24 }
25}
26
27
28const ClientSocket& ClientSocket::operator << ( const std::string& s ) const
29{
30 if ( ! Socket::send ( s ) )
31 {
32 // throw SocketException ( "Could not write to socket." );
33 }
34
35 return *this;
36
37}
38
39
40const ClientSocket& ClientSocket::operator >> ( std::string& s ) const
41{
42 if ( ! Socket::recv ( s ) )
43 {
44 // throw SocketException ( "Could not read from socket." );
45 }
46
47 return *this;
48}
49
50
51void ClientSocket::recv( std::string& s )
52{
53 if ( ! Socket::recv ( s ) )
54 {
55 sleep(1);
56
57 if (! Socket::shutdown() ) std::cout << "shutdown impossible.\n";
58
59 if (! Socket::create() ) std::cout << "create impossible.\n";
60
61 if (! Socket::connect((std::string)"192.168.0.1", 8000)) { std::cout << "connect impossible.\n"; Socket::shutdown(); } else { std::cout << "Reconnexion reussie.\n"; }
62 }
63}
64
Note: See TracBrowser for help on using the repository browser.