Commit 825795a2 authored by Jonas Stienen's avatar Jonas Stienen
Browse files

aktueller stand netzwerkproblem

parent 219f28be
......@@ -88,7 +88,7 @@ void CITANetAudioMessage::WriteMessage()
std::cout << "CITANetAudioMessage [ Writing] " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
#endif
//try
try
{
int iRawBufferSize = m_oOutgoing.GetBufferSize();
int nRet = m_pConnection->Send( m_oOutgoing.GetBuffer(), iRawBufferSize );
......
#include <cassert>
#include <iostream>
#include <string>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Concurrency/VistaThread.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaBase/VistaStreamUtils.h>
using namespace std;
static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
static int g_iRepetitions = 10;
class CServer : public VistaThreadLoop
class CServer : public VistaThread
{
public:
CServer()
{
m_pServer = new VistaTCPServer( g_sServerName, g_iServerPort, 1 );
Run();
}
};
~CServer()
{
delete m_pServer;
}
};
bool LoopBody()
void ThreadBody()
{
cout << "[ Server ] Waiting for connections" << endl;
VistaTCPSocket* pSocket = m_pServer->GetNextClient();
VistaTimeUtils::Sleep( 100 ); // Sync couts
cout << "[ Server ] Connected." << endl;
vstr::out() << "[ Server ] Connected." << endl;
size_t nGetReceiveBufferSize = pSocket->GetReceiveBufferSize();
cout << "[ Server ] " << nGetReceiveBufferSize << " receive buffer size" << endl;
long nIncomingBytes = pSocket->WaitForIncomingData( 0 );
cout << "[ Server ] " << nIncomingBytes << " incoming bytes" << endl;
vstr::out() << "[ Server ] " << nGetReceiveBufferSize << " receive buffer size" << endl;
// Two-step receiving
int iPayloadDataSize;
int iIncomingBytes = pSocket->ReceiveRaw( &iPayloadDataSize, sizeof( int ) );
cout << "[ Server ] Expecting " << iPayloadDataSize << " bytes to come." << endl;
vector< char > vdIncomingData( iPayloadDataSize );
int iBytesReceivedTotal = pSocket->ReceiveRaw( &vdIncomingData[ 0 ], iPayloadDataSize );
cout << "[ Server ] Received " << iBytesReceivedTotal << " bytes, so far." << endl;
vector< char > vdIncomingData;
while( iPayloadDataSize != iBytesReceivedTotal )
bool bRepeat = true;
while( bRepeat )
{
int iBytesReceived = pSocket->ReceiveRaw( &vdIncomingData[ iBytesReceivedTotal ], iPayloadDataSize );
iBytesReceivedTotal += iBytesReceived;
cout << "[ Server ] Further " << iBytesReceived << " bytes incoming" << endl;
long nIncomingBytes = pSocket->WaitForIncomingData( 0 );
vstr::out() << "[ Server ] " << nIncomingBytes << " incoming bytes" << endl;
// Two-step receiving
int iPayloadDataSize;
int iBytesRead = pSocket->ReceiveRaw( &iPayloadDataSize, sizeof( int ) );
assert( iBytesRead == sizeof( int ) );
vstr::out() << "[ Server ] Expecting " << iPayloadDataSize << " bytes to come." << endl;
if( iPayloadDataSize > vdIncomingData.size() )
vdIncomingData.resize( iPayloadDataSize );
int iBytesReceivedTotal = 0;
while( iPayloadDataSize != iBytesReceivedTotal )
{
int iBytesReceived = pSocket->ReceiveRaw( &vdIncomingData[ iBytesReceivedTotal ], iPayloadDataSize );
iBytesReceivedTotal += iBytesReceived;
vstr::out() << "[ Server ] " << setw( 3 ) << std::floor( iBytesReceivedTotal / float( iPayloadDataSize ) * 100.0f ) << "% transmitted" << endl;
}
assert( vdIncomingData[ 0 ] == 1 );
assert( vdIncomingData[ vdIncomingData.size() - 2 ] == -1 );
vstr::out() << "[ Server ] Received all data and content appears valid!" << endl;
vstr::out() << "[ Server ] Sending acknowledge flag" << endl;
bool bTransmissionDone = true;
pSocket->SendRaw( &bTransmissionDone, sizeof( bool ) );
iBytesRead = pSocket->ReceiveRaw( &bRepeat, sizeof( bool ) );
if( bRepeat )
vstr::out() << "[ Server ] Repeating" << endl;
}
assert( vdIncomingData[ 0 ] == 1 );
assert( vdIncomingData[ vdIncomingData.size() - 2 ] == -1 );
cout << "[ Server ] Received all data and content appears valid!" << endl;
VistaTimeUtils::Sleep( 200 );
cout << "[ Server ] Sending acknowledge flag" << endl;
bool bAck = false;
pSocket->SendRaw( &bAck, 1 );
return false;
}
vstr::out() << "[ Server ] Closing." << endl;
};
private:
VistaTCPServer* m_pServer;
......@@ -78,38 +85,42 @@ private:
int main( int , char** )
{
CServer oServer;
VistaTimeUtils::Sleep( 100 ); // Sync couts
VistaConnectionIP oConnection( VistaConnectionIP::CT_TCP, g_sServerName, g_iServerPort);
if( !oConnection.GetIsConnected() )
{
cerr << "[ Client ] Connection failed" << endl;
vstr::out() << "[ Client ] Connection failed" << endl;
return 255;
}
cout << "[ Client ] Connection established" << endl;
VistaTimeUtils::Sleep( 500 );
cout << "[ Client ] Client sending data" << endl;
VistaTimeUtils::Sleep( 500 );
cout << "[ Client ] Connection is buffering: " << ( oConnection.GetIsBuffering() ? "yes" : "no" ) << endl;
size_t l = 1523633239; // > MTU?
vector< char > vdData( l + 4 );
int* piDataSize = ( int* ) &vdData[0];
*piDataSize = unsigned int( l ); // Send data size as first block
vdData[ 1 * sizeof( int ) + 0 ] = 1; // First entry one (just for fun)
vdData[ vdData.size() - 2 ] = -1; // Second last entry -1 (just for fun)
void* pData = (void*) &vdData[0];
oConnection.Send( pData, int( vdData.size() ) ); // SendRaw?
vstr::out() << "[ Client ] Connection established" << endl;
vstr::out() << "[ Client ] Connection is buffering: " << ( oConnection.GetIsBuffering() ? "yes" : "no" ) << endl;
bool bAck;
oConnection.ReadBool( bAck );
VistaTimeUtils::Sleep( 100 ); // cout sync
cout << "[ Client ] Received acknowledge flag '" << bAck << "', closing." << endl;
int i = 0;
while( i++ <= g_iRepetitions )
{
vstr::out() << "[ Client ] Client sending data now." << endl;
size_t l = 1523633239; // > MTU?
vector< char > vdData( l + 4 );
int* piDataSize = ( int* ) &vdData[ 0 ];
*piDataSize = unsigned int( l ); // Send data size as first block
vdData[ 1 * sizeof( int ) + 0 ] = 1; // First entry one (just for fun)
vdData[ vdData.size() - 2 ] = -1; // Second last entry -1 (just for fun)
void* pData = ( void* ) &vdData[ 0 ];
oConnection.Send( pData, int( vdData.size() ) ); // SendRaw?
bool bAck;
oConnection.ReadBool( bAck );
if( !bAck )
vstr::out() << "[ Client ] Received negative acknowledge flag" << endl;
else
vstr::out() << "[ Client ] Received positive acknowledge flag" << endl;
bool bRepeat = ( i <= g_iRepetitions );
oConnection.Send( &bRepeat, sizeof( bool ) );
}
oConnection.Close( false );
......
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