procedure TFormMain.IdTCPServerExecute(AThread: TIdPeerThread); var sCommand: string; begin with AThread.Connection do begin sCommand := ReadLn(); FLogEntry := sCommand + ' 来自于主机 ' + AThread.Connection.Socket.Binding.PeerIP; AThread.Synchronize(AddLogEntry); if AnsiStartsText('DATA ', sCommand) then begin FReceived := RightStr(sCommand, Length(sCommand)-5); WriteLn('200: 数据接收成功!'); AThread.Synchronize(DisplayData); end else if SameText(sCommand, 'QUIT') then begin FLogEntry := '断开同主机 ' + AThread.Connection.Socket.Binding.PeerIP + ' 的连接!'; AThread.Synchronize(AddLogEntry); Disconnect; end else begin WriteLn('500: 无法识别的命令!'); FLogEntry := '无法识别命令:' + sCommand; AThread.Synchronize(AddLogEntry); end;//endif end; end;
procedure TFormMain.DisplayData(); begin EdtData.Text := FReceived; end;
procedure TFormMain.AddLogEntry(); begin LbLog.Items.Add(FLogEntry); end;