-
Notifications
You must be signed in to change notification settings - Fork 4
/
igtlMexClientSocket.cpp
81 lines (62 loc) · 2.38 KB
/
igtlMexClientSocket.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
77
78
79
80
/*=========================================================================
Program: Open IGT Link Library
Module: $RCSfile: $
Language: C++
Date: $Date: $
Version: $Revision: $
Copyright (c) Insight Software Consortium. 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.
=========================================================================*/
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkClientSocket.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "igtlMexClientSocket.h"
namespace igtl
{
//-----------------------------------------------------------------------------
MexClientSocket::MexClientSocket()
{
}
//-----------------------------------------------------------------------------
MexClientSocket::~MexClientSocket()
{
}
//-----------------------------------------------------------------------------
int MexClientSocket::ConnectToServer(const char* hostName, int port)
{
if (this->m_SocketDescriptor != -1)
{
igtlWarningMacro("Client connection already exists. Closing it.");
this->CloseSocket(this->m_SocketDescriptor);
this->m_SocketDescriptor = -1;
}
this->m_SocketDescriptor = this->CreateSocket();
if (!this->m_SocketDescriptor)
{
igtlErrorMacro("Failed to create socket.");
return -1;
}
if (this->Connect(this->m_SocketDescriptor, hostName, port) == -1)
{
this->CloseSocket(this->m_SocketDescriptor);
this->m_SocketDescriptor = -1;
igtlErrorMacro("Failed to connect to server " << hostName << ":" << port);
return -1;
}
return 0;
}
//-----------------------------------------------------------------------------
void MexClientSocket::PrintSelf(std::ostream& os)
{
this->Superclass::PrintSelf(os);
}
} // end of igtl namespace