J
jack_fang
Unregistered / Unconfirmed
GUEST, unregistred user!
服务器端发来数据,前2字节是标志这个包的大小,我接收端应该怎么写?
procedure TForm1.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
len:word;
buf:array of char;
msg:string;
begin
try
memo1.Lines.Add(inttostr(socket.ReceiveLength));
Socket.ReceiveBuf(len, 2);
memo1.Lines.Add('len:' + inttostr(len));
if len < 1 then Exit;
setlength(buf, len);
Socket.ReceiveBuf(buf[0], len);
setlength(msg, len);
Move(buf[0], msg[1], len);
MemReadMsg.Lines.Add(msg);
except
end;
end;
怎么得到前2个字节
procedure TForm1.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
len:word;
buf:array of char;
msg:string;
begin
try
memo1.Lines.Add(inttostr(socket.ReceiveLength));
Socket.ReceiveBuf(len, 2);
memo1.Lines.Add('len:' + inttostr(len));
if len < 1 then Exit;
setlength(buf, len);
Socket.ReceiveBuf(buf[0], len);
setlength(msg, len);
Move(buf[0], msg[1], len);
MemReadMsg.Lines.Add(msg);
except
end;
end;
怎么得到前2个字节