void __fastcall TForm1::Button1Click(TObject *Sender)
{
int size = MemoEnter->GetTextLen() + 1;
wchar_t *szBuff = new wchar_t[size];
memset(szBuff, 0, sizeof(szBuff));
MemoEnter->GetTextBuf((wchar_t *)szBuff, size);
TcpClient->SendBuf(szBuff, sizeof(szBuff));
LogOut->Lines->Add(szBuff);
delete []szBuff;
}
Why doesn't TcpClient send anything? Server is ok. connection is ok. Telnet sends data to the server but this code does not.
Guys! i tried to
TcpClient->SendBuf("fsd", 3);
and still got nothing
Your use of
sizeof()is definately the problem. You are sending your data specifying the size of the pointer that points at the buffer, not the size of the buffer itself. The size of a pointer is 4 in 32-bit and 8 in 64-bit. You need to use the actual buffer size instead of the pointer size.Rather than using the
new[]operator, you should use the VCL'sStringclass instead, eg:Note that
Stringis an alias forUnicodeString. If the receiver is not expectingUTF-16encoded data, then you need to convert the data to another encoding before you send it, eg:Or:
Or: