Skip to content
Snippets Groups Projects
Commit dd34eff7 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Finished client server init until some values are exchanged.

parent d37462eb
No related branches found
No related tags found
No related merge requests found
......@@ -10,8 +10,8 @@
static int S_nMessageIds = 0;
CITANetAudioMessage::CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwapBehavior bSwapBuffers )
: m_vecIncomingBuffer()
, m_oOutgoing()
: m_vecIncomingBuffer( 2048 )
, m_oOutgoing( 2048 )
, m_pConnection( NULL )
{
m_oOutgoing.SetByteorderSwapFlag( bSwapBuffers );
......@@ -37,7 +37,6 @@ void CITANetAudioMessage::ResetMessage()
m_oOutgoing.ClearBuffer();
m_oOutgoing.WriteInt32( 0 ); // size dummy
m_oOutgoing.WriteInt32( 0 ); // type dummy
m_oOutgoing.WriteInt32( 0 ); // exceptmode dummy
m_oOutgoing.WriteInt32( 0 ); // ID
m_oIncoming.SetBuffer( NULL, 0 );
......@@ -82,8 +81,8 @@ void CITANetAudioMessage::WriteMessage()
try
{
int nRet = m_pConnection->WriteRawBuffer( m_oOutgoing.GetBuffer(),
m_oOutgoing.GetBufferSize() );
int iRawBufferSize = m_oOutgoing.GetBufferSize();
int nRet = m_pConnection->WriteRawBuffer( m_oOutgoing.GetBuffer(), iRawBufferSize );
m_pConnection->WaitForSendFinish();
if( nRet != m_oOutgoing.GetBufferSize() )
ITA_EXCEPT1( NETWORK_ERROR, "Could not write the expected number of bytes" );
......@@ -196,6 +195,7 @@ void CITANetAudioMessage::ReadAnswer()
if( nMessageSize > ( int ) m_vecIncomingBuffer.size() )
m_vecIncomingBuffer.resize( nMessageSize );
// jst: hier nicht while( nReturn < nMessageSize) ReadRawBuffer??
nReturn = m_pConnection->ReadRawBuffer( &m_vecIncomingBuffer[ 0 ], nMessageSize );
if( nReturn != nMessageSize )
ITA_EXCEPT1( UNKNOWN, "Protokoll error, Received less bytes than expected" );
......@@ -216,7 +216,6 @@ void CITANetAudioMessage::ReadAnswer()
try
{
m_nAnswerType = ReadInt(); // TODO: assert weg, dafr Kontrolle falls Server crasht<
ReadInt(); // protocol overhead - just read and ignore
int nMessageID = ReadInt();
assert( nMessageID == m_nMessageId );
m_nMessageId = nMessageID;
......
......@@ -44,18 +44,21 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
// Validate streaming parameters of server and client
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_OPEN );
m_pMessage->WriteStreamingParameters( m_oClientParams );
//m_pMessage->WriteStreamingParameters( m_oClientParams ); // Not yet
m_pMessage->WriteInt( 42 );
m_pMessage->WriteMessage();
m_pMessage->ReadAnswer();
assert( m_pMessage->GetAnswerType() == CITANetAudioProtocol::NP_SERVER_OPEN );
bool bOK = m_pMessage->ReadBool();
int i42 = m_pMessage->ReadInt();
/* Not yet
CITANetAudioProtocol::StreamingParameters oServerParams = m_pMessage->ReadStreamingParameters();
if( oServerParams == m_oClientParams )
m_oServerParams = oServerParams;
else
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming parameters of network audio server and client do not match." );
*/
Run();
......
......@@ -24,35 +24,34 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
, m_pConnection( NULL )
{
m_pNetAudioServer = new CITANetAudioServer();
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
}
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
{
// TODO: vorrckgabe noch anfangen zu senden (Samples)
if( m_pNetAudioServer->Start( sAddress, iPort ) )
{
m_pConnection = m_pNetAudioServer->GetConnection();
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection );
m_pMessage->ReadMessage();
if( !m_pNetAudioServer->Start( sAddress, iPort ) ) // blocking
return false;
int nMT = m_pMessage->GetMessageType();
assert( nMT == CITANetAudioProtocol::NP_CLIENT_OPEN );
m_pConnection = m_pNetAudioServer->GetConnection();
CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters();
m_pMessage = new CITANetAudioMessage( m_pConnection->GetByteorderSwapFlag() );
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection );
m_pMessage->ReadMessage(); // blocking
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_OPEN );
m_pMessage->WriteBool( true );
m_pMessage->WriteAnswer();
int nMT = m_pMessage->GetMessageType();
assert( nMT == CITANetAudioProtocol::NP_CLIENT_OPEN );
int i42 = m_pMessage->ReadInt();
Run();
//CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters();
return true;
}
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_OPEN );
m_pMessage->WriteInt( 2 * 42 );
m_pMessage->WriteAnswer();
return false;
Run();
return true;
}
bool CITANetAudioStreamingServer::IsClientConnected() const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment