-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathigtlTCPConnectorServer.cxx
102 lines (71 loc) · 2.18 KB
/
igtlTCPConnectorServer.cxx
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*=========================================================================
Program: Connector Server Class for OpenIGTLink Simulator
Language: C++
Copyright (c) Brigham and Women's Hospital. All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "igtlSocket.h"
#include <string.h>
#include "igtlTCPConnectorServer.h"
namespace igtl
{
//-----------------------------------------------------------------------------
TCPConnectorServer::TCPConnectorServer()
{
this->ServerSocket = igtl::ServerSocket::New();
this->ServerSocket->DebugOff();
}
//-----------------------------------------------------------------------------
TCPConnectorServer::~TCPConnectorServer()
{
}
//-----------------------------------------------------------------------------
void TCPConnectorServer::PrintSelf(std::ostream& os) const
{
this->Superclass::PrintSelf(os);
}
//-----------------------------------------------------------------------------
int TCPConnectorServer::Initialize()
{
if (this->ServerSocket->CreateServer(this->Port))
{
return 0;
}
return 1;
}
//-----------------------------------------------------------------------------
int TCPConnectorServer::WaitForConnection()
{
this->Socket = NULL;
if (this->ServerSocket.IsNotNull())
{
this->Socket = this->ServerSocket->WaitForConnection(1000);
}
if (this->Socket.IsNotNull() && this->Socket->GetConnected()) // if client connected
{
this->Socket->DebugOff();
return 1;
}
return 0;
}
//-----------------------------------------------------------------------------
int TCPConnectorServer::CloseConnection()
{
if (this->Socket.IsNotNull())
{
this->Socket->CloseSocket();
}
return 0;
}
//-----------------------------------------------------------------------------
int TCPConnectorServer::Finalize()
{
if (this->ServerSocket.IsNotNull())
{
this->ServerSocket->CloseSocket();
}
return 0;
}
} // End of igtl namespace