R
rlz
Unregistered / Unconfirmed
GUEST, unregistred user!
我定义了一个类型:
type
TMyrec = record
Code: Integer;
IP: String[15];
Password: String[15];
State: Byte;
Port: Word;
end;
发送端如下:
var
login:tmyrec;
login.Code :='111';
login.Password :='12345678' ;
login.Port :=8090;
login.State :=1;
AStream := TMemoryStream.Create;
try
AStream.Write(login, nBufferSize);
AStream.Position := 0;
udpclient.SendBuffer(AStream.Memory^, AStream.Size);
finally
AStream.Free;
end;
接受时这样处理:
adata:stream;
iCommand: Integer;
begin
CopyMemory(@iCommand, AData, SizeOf(iCommand));
LogginRec := PLogginRec(Adata)^;
Memo1.Lines .Add('code: ' + IntToStr(LogginRec.Code) );
Memo1.Lines .Add('password:'+login.password);
Memo1.Lines .Add('port:'+inttostr(login.port));
Memo1.Lines .Add('state:'+inttostr(login.state));
adata.Free;
end;
为什么看到的是乱码?请大侠指教。
说明:我用的是idudpclient发送的,收是用idudpserver.
type
TMyrec = record
Code: Integer;
IP: String[15];
Password: String[15];
State: Byte;
Port: Word;
end;
发送端如下:
var
login:tmyrec;
login.Code :='111';
login.Password :='12345678' ;
login.Port :=8090;
login.State :=1;
AStream := TMemoryStream.Create;
try
AStream.Write(login, nBufferSize);
AStream.Position := 0;
udpclient.SendBuffer(AStream.Memory^, AStream.Size);
finally
AStream.Free;
end;
接受时这样处理:
adata:stream;
iCommand: Integer;
begin
CopyMemory(@iCommand, AData, SizeOf(iCommand));
LogginRec := PLogginRec(Adata)^;
Memo1.Lines .Add('code: ' + IntToStr(LogginRec.Code) );
Memo1.Lines .Add('password:'+login.password);
Memo1.Lines .Add('port:'+inttostr(login.port));
Memo1.Lines .Add('state:'+inttostr(login.state));
adata.Free;
end;
为什么看到的是乱码?请大侠指教。
说明:我用的是idudpclient发送的,收是用idudpserver.