Commit 5885c095 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding network tests using Vista Server&Client

parent 268ace49
......@@ -123,3 +123,4 @@ set_property( TARGET StreamProbeTest PROPERTY FOLDER "ITATests/ITADataSources" )
# Portaudio tests
add_subdirectory( "ITAPortaudioTests" )
add_subdirectory( "VistaNetTest" )
......@@ -14,7 +14,7 @@ void record() {
ITAPortaudioInterface ITAPA(dSampleRate, iBlockSize);
int iInputDevice = ITAPA.GetDefaultInputDevice();
iInputDevice = 4;
//iInputDevice = 4;
ITAPortaudioInterface::ITA_PA_ERRORCODE err;
err = ITAPA.Initialize(iInputDevice);
......
cmake_minimum_required( VERSION 2.9 )
if( NOT ITADATASOURCES_COMMON_BUILD )
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
endif()
vista_use_package( VistaCoreLibs REQUIRED COMPONENTS VistaInterProcComm FIND_DEPENDENCIES )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
add_executable( ITAVistaNetTest VistaNetTest.cpp )
target_link_libraries( ITAVistaNetTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITAVistaNetTest )
vista_install( ITAVistaNetTest )
vista_create_default_info_file( ITAVistaNetTest )
set_property( TARGET ITAVistaNetTest PROPERTY FOLDER "ITATests/ITADataSources" )
add_executable( ITAVistaNetClient VistaNetClient.cpp )
target_link_libraries( ITAVistaNetClient ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_set_target_msvc_arguments( ITAVistaNetClient "localhost 12343" )
vista_configure_app( ITAVistaNetClient )
vista_install( ITAVistaNetClient )
vista_create_default_info_file( ITAVistaNetClient )
set_property( TARGET ITAVistaNetClient PROPERTY FOLDER "ITATests/ITADataSources" )
add_executable( ITAVistaNetServer VistaNetServer.cpp )
target_link_libraries( ITAVistaNetServer ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_set_target_msvc_arguments( ITAVistaNetServer "localhost 12343" )
vista_configure_app( ITAVistaNetServer )
vista_install( ITAVistaNetServer )
vista_create_default_info_file( ITAVistaNetServer )
set_property( TARGET ITAVistaNetServer PROPERTY FOLDER "ITATests/ITADataSources" )
#include <iostream>
#include <string>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
#include <ITAStringUtils.h>
#include <ITAStopwatch.h>
#include <ITAStringUtils.h>
int main(int argc, char** argv) {
if( argc != 3 )
{
std::cout << "Syntax error: VistaNetClient SERVER PORT" << std::endl;
return 255;
}
std::string sServerName = argv[1];
int iServerPort = StringToInt( std::string( argv[2] ) );
std::cout << "Attempting to connect to '" << sServerName << ":" << iServerPort << "'" << std::endl;
ITAStopWatch sw; sw.start();
VistaConnectionIP oCommandChannelConnection( VistaConnectionIP::CT_TCP, sServerName, iServerPort);
if( oCommandChannelConnection.GetIsConnected() == false )
{
std::cerr << "Connection error, exiting." << std::endl;
return 255;
}
std::string sLocalAddress;
oCommandChannelConnection.GetLocalAddress().GetIPAddress().GetAddressString( sLocalAddress );
int iBackchannelPort = 12481;
VistaTCPServer oServer( sLocalAddress, iBackchannelPort, 1 );
if( oServer.GetIsValid() == false)
{
std::cerr << "Could not start server" << std::endl;
return 255;
}
// Transmit port on command channel
oCommandChannelConnection.WriteRawBuffer( &iBackchannelPort, 8 );
VistaTCPSocket* pSocket = oServer.GetNextClient();
unsigned long l = pSocket->WaitForIncomingData( 0 );
if( l == sizeof( VistaType::byte ) )
{
bool bAck;
pSocket->ReceiveRaw( &bAck, l );
std::cout << "Client received acknowledge flag '" << bAck << "'" << std::endl;
}
oCommandChannelConnection.Close( false );
return 0;
}
#include <iostream>
#include <string>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
//#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
#include <ITAStringUtils.h>
int main(int argc, char** argv) {
if( argc != 3 )
{
std::cerr << "Syntax error: VistaNetServer SERVER PORT" << std::endl;
return 255;
}
std::string sServerName = argv[1];
int iServerPort = StringToInt( std::string( argv[2] ) );
std::cout << "Setting up server command channel on '" << sServerName << ":" << iServerPort << "'" << std::endl;
VistaTCPServer oServer( sServerName, iServerPort, 1 );
std::cout << "Waiting for connection" << std::endl;
VistaTCPSocket* pSocket = oServer.GetNextClient();
if( oServer.GetIsValid() == false)
{
std::cerr << "Could not start server" << std::endl;
return 255;
}
std::cout << "Waiting for result channel port" << std::endl;
unsigned long l = pSocket->WaitForIncomingData( 0 );
if( l == 8 )
{
unsigned long iRequestedResultChannelPort;
pSocket->ReceiveRaw( &iRequestedResultChannelPort, 8 );
std::string sRemoteAddress;
VistaSocketAddress sAddr;
pSocket->GetPeerSockName( sAddr );
sAddr.GetIPAddress().GetAddressString( sRemoteAddress );
VistaConnectionIP oConnection( VistaConnectionIP::CT_TCP, sRemoteAddress, iRequestedResultChannelPort);
bool bAck = oConnection.GetIsConnected();
oConnection.Send(&bAck, sizeof( bool ) );
oConnection.WaitForSendFinish( 0 );
std::cout << "Result channel connection successfully established" << std::endl;
oConnection.Close( false );
}
pSocket->CloseSocket();
return 0;
}
#include <cassert>
#include <iostream>
#include <string>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
using namespace std;
static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
class CServer : public VistaThreadLoop
{
public:
CServer()
{
m_pServer = new VistaTCPServer( g_sServerName, g_iServerPort, 1 );
Run();
}
~CServer() {
delete m_pServer;
}
bool LoopBody()
{
VistaTCPSocket* pSocket = m_pServer->GetNextClient();
VistaTimeUtils::Sleep( 100 ); // Sync couts
size_t nGetReceiveBufferSize = pSocket->GetReceiveBufferSize();
long nIncomingBytes = pSocket->WaitForIncomingData( 0 );
cout << "Server incoming bytes: " << nIncomingBytes << " bytes" << endl;
if( nGetReceiveBufferSize == nIncomingBytes )
cout << "Warning: payload as long as receiver buffer size ... problem will occur!" << endl;
char* buf = new char[ nIncomingBytes ];
long nIncomingBytes2 = pSocket->WaitForIncomingData( 0 );
int iBytesReceived = pSocket->ReceiveRaw( buf, nIncomingBytes );
vector< char > vdIncomingData( iBytesReceived );
for( size_t i=0; i < vdIncomingData.size(); i++ )
vdIncomingData[i] = buf[ i ];
delete[] buf;
assert( vdIncomingData[0] == 1 );
assert( vdIncomingData[ vdIncomingData.size() -2 ] == -1 );
VistaTimeUtils::Sleep( 200 );
cout << "Server sending acknowledge flag" << endl;
bool bAck = false;
pSocket->SendRaw( &bAck, 1 );
return false;
}
private:
VistaTCPServer* m_pServer;
};
int main( int , char** )
{
CServer oServer;
VistaConnectionIP oConnection( VistaConnectionIP::CT_TCP, g_sServerName, g_iServerPort);
if( oConnection.GetIsConnected() )
{
cout << "Connection established" << endl;
VistaTimeUtils::Sleep( 500 );
cout << "Client sending data" << endl;
VistaTimeUtils::Sleep( 500 );
cout << "Connection is buffering: " << ( oConnection.GetIsBuffering() ? "yes" : "no" ) << endl;
size_t l = 10000; // > MTU?
vector< char > vdData( l );
vdData[ 0 ] = 1; // First entry one
vdData[ vdData.size() - 2 ] = -1; // Last entry -1
void* pData = (void*) &vdData[0];
oConnection.Send( pData, int( vdData.size() ) ); // SendRaw?
bool bAck;
oConnection.ReadBool( bAck );
cout << "Client received acknowledge flag '" << bAck << "'" << endl;
oConnection.Close( false );
}
else
{
cerr << "Connection failed" << endl;
return 255;
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment