P
Philipp Jacobi
Hello,
i am writing an application where a client communicates with a server using
TCP/IP and System::Net::Socket. I am using C++ .NET.
When the buffer which i will receive is greater than 8192 Byte
(Socket Standard Buffersize) and the client calls begin receive again, it
seems that Socket::Receive()
does not return. But when i stop the Thread with Thread::Sleep() before
calling Receive again, all works fine.
Here are 2 Code Snippets:
The first Example does not work when the buffer is greater than 8192 and the
second works ? !!!
Example 1: (Does not work)
if ( ( BytesReceived = this->ConnectionSocket->Receive(ReceiveBuffer,
ReceiveBuffer->Length, SocketFlags::None) ) > 0 )
{
// Decode String
sb->Append( enc->GetString(ReceiveBuffer, 0, BytesReceived) );
while ( this->ConnectionSocket->Available > 0 )
{
BytesReceived = this->ConnectionSocket->Receive(ReceiveBuffer,
ReceiveBuffer->Length, SocketFlags::None);
sb->Append(enc->GetString(ReceiveBuffer, 0, BytesReceived));
}
}
Example 2: ( Works fine )
if ( ( BytesReceived = this->ConnectionSocket->Receive(ReceiveBuffer,
ReceiveBuffer->Length, SocketFlags::None) ) > 0 )
{
// Decode String
sb->Append( enc->GetString(ReceiveBuffer, 0, BytesReceived) );
while ( this->ConnectionSocket->Available > 0 )
{
Thread::Sleep(10);
BytesReceived = this->ConnectionSocket->Receive(ReceiveBuffer,
ReceiveBuffer->Length, SocketFlags::None);
sb->Append(enc->GetString(ReceiveBuffer, 0, BytesReceived));
}
}
Any ideas about this behaviour ?
Thanks in Advance !
Philipp Jacobi
i am writing an application where a client communicates with a server using
TCP/IP and System::Net::Socket. I am using C++ .NET.
When the buffer which i will receive is greater than 8192 Byte
(Socket Standard Buffersize) and the client calls begin receive again, it
seems that Socket::Receive()
does not return. But when i stop the Thread with Thread::Sleep() before
calling Receive again, all works fine.
Here are 2 Code Snippets:
The first Example does not work when the buffer is greater than 8192 and the
second works ? !!!
Example 1: (Does not work)
if ( ( BytesReceived = this->ConnectionSocket->Receive(ReceiveBuffer,
ReceiveBuffer->Length, SocketFlags::None) ) > 0 )
{
// Decode String
sb->Append( enc->GetString(ReceiveBuffer, 0, BytesReceived) );
while ( this->ConnectionSocket->Available > 0 )
{
BytesReceived = this->ConnectionSocket->Receive(ReceiveBuffer,
ReceiveBuffer->Length, SocketFlags::None);
sb->Append(enc->GetString(ReceiveBuffer, 0, BytesReceived));
}
}
Example 2: ( Works fine )
if ( ( BytesReceived = this->ConnectionSocket->Receive(ReceiveBuffer,
ReceiveBuffer->Length, SocketFlags::None) ) > 0 )
{
// Decode String
sb->Append( enc->GetString(ReceiveBuffer, 0, BytesReceived) );
while ( this->ConnectionSocket->Available > 0 )
{
Thread::Sleep(10);
BytesReceived = this->ConnectionSocket->Receive(ReceiveBuffer,
ReceiveBuffer->Length, SocketFlags::None);
sb->Append(enc->GetString(ReceiveBuffer, 0, BytesReceived));
}
}
Any ideas about this behaviour ?
Thanks in Advance !
Philipp Jacobi