Hi folks,
I'm triying to send message form the client to the server in BCB 6.0 but when I send the message I got immediately "Error receiving" I couldn't find where is the wrong..
Any answer will appreciate..
My code look like this
--- client ---
Code:
bool __fastcall SendBuffer(TCustomWinSocket *Socket, void *Buffer, int
Length)
{
int Sent = 0;
int Total_Sent = 0;
BYTE *Buf = (LPBYTE)Buffer;
while( Total_Sent < Length )
{
Sent = Socket->SendBuf(&Buf[Total_Sent], Length - Total_Sent);
if( Sent <= 0 )
{
if( WSAGetLastError() == WSAEWOULDBLOCK )
continue;
return false;
}
Total_Sent += Sent;
}
return true;
}
//...
AnsiString text = Edit1->Text;
int length = text.Length();
bool ok = SendBuffer(Form1->ClientSocket1->Socket, &length,
sizeof(int));
if( ok )
ok = SendBuffer(Form1->ClientSocket1->Socket, text.c_str(), length);
if( !ok )
ShowMessage("Error");
--- server ---
bool __fastcall ReadBuffer(TCustomWinSocket *Socket, void *Buffer, int
Length)
{
int Read = 0;
int Total_Read = 0;
BYTE *Buf = (LPBYTE)Buffer;
while( Total_Read < Length )
{
Read = Socket->ReceiveBuf(&Buf[Total_Read], Length -
Total_Read);
if( Read <= 0 )
{
if( WSAGetLastError() == WSAEWOULDBLOCK )
continue;
return false;
}
Total_Read += Read;
}
return true;
}
//...
AnsiString buffer;
int length = 0;
bool ok = ReadBuffer(Socket, &length, sizeof(int));
if( ok )
{
buffer.SetLength(length);
ok = ReadBuffer(Socket, buffer.c_str(), length);
}
if( !ok )
ShowMessage("Error receiving");
Thanks in Advance
BigSky_(*