A
atomy
Unregistered / Unconfirmed
GUEST, unregistred user!
这里部分原代码.
procedure TForm1.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
rechar;
sbuf:string;
relong:integer;
begin
re:=nil;
while socket.ReceiveLength>0 do
begin
//申请内存
re:=AllocMem(socket.receivelength);
TRY
relong:=socket.ReceiveLength;
Socket.ReceiveBuf(re^,Socket.receivelength);
sBuf:=strpas(re);
Setlength(sbuf,relong);
//count lenght
TotalLen:=TotalLen+ relong;
S1.Panels.Items[1].Text:='Total Received (Byte): ' + IntToStr(TotalLen);
S1.Update();
FINALLY
freemem(re);
END;
M1.Lines.Add(sbuf);
end;
end;
我想问为什么要申请内存???这样做有什么用?书里没有讲到.还有就是socket服务端如何与多个客户端的其中一个指定
客户端通讯?
procedure TForm1.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
rechar;
sbuf:string;
relong:integer;
begin
re:=nil;
while socket.ReceiveLength>0 do
begin
//申请内存
re:=AllocMem(socket.receivelength);
TRY
relong:=socket.ReceiveLength;
Socket.ReceiveBuf(re^,Socket.receivelength);
sBuf:=strpas(re);
Setlength(sbuf,relong);
//count lenght
TotalLen:=TotalLen+ relong;
S1.Panels.Items[1].Text:='Total Received (Byte): ' + IntToStr(TotalLen);
S1.Update();
FINALLY
freemem(re);
END;
M1.Lines.Add(sbuf);
end;
end;
我想问为什么要申请内存???这样做有什么用?书里没有讲到.还有就是socket服务端如何与多个客户端的其中一个指定
客户端通讯?