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
|
/*=========================================================================
Program: OpenIGTLink -- Example for Sending Status Messasge
Language: C++
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.
=========================================================================*/
#include <iostream>
#include <math.h>
#include <cstdlib>
#include "igtlOSUtil.h"
#include "igtlStatusMessage.h"
#include "igtlClientSocket.h"
//
// Test comment
//
int main(int argc, char* argv[])
{
//------------------------------------------------------------
// Parse Arguments
if (argc != 3) // check number of arguments
{
// If not correct, print usage
std::cerr << "Usage: " << argv[0] << " <hostname> <port>" << std::endl;
std::cerr << " <hostname> : IP or host name" << std::endl;
std::cerr << " <port> : Port # (18944 in Slicer default)" << std::endl;
exit(0);
}
char* hostname = argv[1];
int port = atoi(argv[2]);
int interval = (int) (1000);
//------------------------------------------------------------
// Establish Connection
igtl::ClientSocket::Pointer socket;
socket = igtl::ClientSocket::New();
int r = socket->ConnectToServer(hostname, port);
if (r != 0)
{
std::cerr << "Cannot connect to the server." << std::endl;
exit(0);
}
//------------------------------------------------------------
// Allocate Status Message Class
igtl::StatusMessage::Pointer statusMsg;
statusMsg = igtl::StatusMessage::New();
statusMsg->SetDeviceName("Device");
//------------------------------------------------------------
// loop
for (int i = 0; i < 100; i ++)
{
statusMsg->SetCode(igtl::StatusMessage::STATUS_OK);
statusMsg->SetSubCode(128);
statusMsg->SetErrorName("OK!");
statusMsg->SetStatusString("This is a test to send status message.");
statusMsg->Pack();
socket->Send(statusMsg->GetPackPointer(), statusMsg->GetPackSize());
igtl::Sleep(interval); // wait
}
//------------------------------------------------------------
// Close connection
socket->CloseSocket();
}
|