-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobocup_ssl_client.cpp
77 lines (68 loc) · 2.13 KB
/
robocup_ssl_client.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//========================================================================
// This software is free: you can redistribute it and/or modify
// it under the terms of the GNU General Public License Version 3,
// as published by the Free Software Foundation.
//
// This software 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// Version 3 in the file COPYING that came with this distribution.
// If not, see <http://www.gnu.org/licenses/>.
//========================================================================
/*!
\file robocup_ssl_client.cpp
\brief C++ Implementation: robocup_ssl_client
\author Stefan Zickler, 2009
*/
//========================================================================
#include "robocup_ssl_client.h"
using namespace std;
RoboCupSSLClient::RoboCupSSLClient(int port,string net_address,string net_interface)
{
_port=port;
_net_address=net_address;
_net_interface=net_interface;
in_buffer=new char[65536];
}
RoboCupSSLClient::~RoboCupSSLClient()
{
delete[] in_buffer;
}
void RoboCupSSLClient::close() {
mc.close();
}
bool RoboCupSSLClient::open(bool blocking) {
close();
if(!mc.open(_port,true,true,blocking)) {
fprintf(stderr,"Unable to open UDP network port: %d\n",_port);
fflush(stderr);
return(false);
}
Net::Address multiaddr,interface;
multiaddr.setHost(_net_address.c_str(),_port);
if(_net_interface.length() > 0){
interface.setHost(_net_interface.c_str(),_port);
}else{
interface.setAny();
}
if(!mc.addMulticast(multiaddr,interface)) {
fprintf(stderr,"Unable to setup UDP multicast\n");
fflush(stderr);
return(false);
}
return(true);
}
bool RoboCupSSLClient::receive(SSL_WrapperPacket & packet) {
Net::Address src;
int r=0;
r = mc.recv(in_buffer,MaxDataGramSize,src);
if (r>0) {
fflush(stdout);
//decode packet:
return packet.ParseFromArray(in_buffer,r);
}
return false;
}