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
|
/*=========================================================================
Program: The OpenIGTLink Library
Language: C++
Web page: http://openigtlink.org/
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 "igtlClientSocket.h"
namespace igtl
{
//-----------------------------------------------------------------------------
ClientSocket::ClientSocket()
{
}
//-----------------------------------------------------------------------------
ClientSocket::~ClientSocket()
{
}
//-----------------------------------------------------------------------------
int ClientSocket::ConnectToServer(const char* hostName, int port, bool logErrorIfServerConnectionFailed /*= true*/)
{
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;
if( logErrorIfServerConnectionFailed )
{
igtlErrorMacro("Failed to connect to server " << hostName << ":" << port);
}
return -1;
}
return 0;
}
//-----------------------------------------------------------------------------
void ClientSocket::PrintSelf(std::ostream& os) const
{
this->Superclass::PrintSelf(os);
}
} // end of igtl namespace
|