What is the right way of send/receive a integer value using native winsock in only one line, similar to C++ code below? i'm tried translate this, but not know if is right. Can someone help me please?
C++:
enum MyEnum { element01, element02 };
int width;
int SendInt(SOCKET sock, int i)
{
return Send(sock, (char *) &i, sizeof(i), 0);
}
if(SendInt(sock, MyEnum::element01) <= 0) return;
if(SendInt(sock, 0) <= 0) return;
if(recv(sock, (char *) &width, sizeof(width), 0) <= 0) return;
Delphi:
type
MyEnum = (element01, element02);
var
Width: Integer;
function SendInt(S: TSocket; I: Integer): Integer;
begin
Result := send(S, PAnsiChar(I)^, Length(IntToStr(I)), 0);
end;
if SendInt(Sock, Integer(MyEnum.element01)) <= 0 then Exit;
if SendInt(Sock, 0) <= 0 then Exit;
if recv(Sock, PAnsiChar(Width)^, Length(IntToStr(Width)), 0) <= 0 then Exit;