All pastes #131186 Raw Edit

Anonymous

public text v1 · immutable
#131186 ·published 2006-08-14 11:46 UTC
rendered paste body
procedure tform1.cread(Sender: TObject; Socket: TCustomWinSocket);
var buf:array[0..4096] of char;
    fs:tmemorystream;
    s:String;
    i:integer;
begin
  windows.beep(500,30);
  if not b then
    begin
      s:=socket.ReceiveText;
      if s[1]='c' then
        memo1.lines.add('command: '+s);
      if s[1]='d' then
        begin
          delete(s,1,1);
          nsize:=strtoint(s);
          memo1.lines.add('data size: '+inttostr(nsize));
          b:=true;
          fs:=tmemorystream.Create;
          cnt:=0;
          fs.position:=0;
        end;
    end
  else
    begin
      i:=socket.ReceiveBuf(buf, sizeof(buf));
      inc(cnt, i);
      fs.WriteBuffer(buf, i);
      memo1.lines.add(inttostr(cnt));
      if cnt>=nsize then
        begin
          memo1.lines.add('data read!');
          fs.SaveToFile(fname);
          b:=false;
        end;
    end;
end;