Einzelnen Beitrag anzeigen

Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#4

Re: Normale TCP connection mit Indy10

  Alt 21. Mai 2010, 07:53
Zitat von Jamah:
Ok. Danke.
Aber wie baue ich das ein? Also wenn ich das in die Prozedur mache, wo der client was sendet, und dann der server was zurückgibt, bleibt das Porgramm stehen.
Ich kann mir schwer vorstellen das es hängt, bur weil Du etwas zum Client schickst.

Ich denke es hängt, weil readln auf Daten wartet.
Zitat von DelphiHilfe:

ReadLn is an overloaded string function used to read a single line of text from values received from the peer connection for the IOHandler.

ReadLn is a String function that returns a a single line from the input buffer maintained for the IOHandler. This variant of the ReadLn method uses the LF character as the end-of-line delimiter, and calls an overloaded variant of the method.

ReadLn retrieves data from InputBuffer until the end-of-line sequence is located, the maximum line length is exceeded, the socket connection is closed, or a timeout occurs. If there is not enough data to satisfy the request, ReadLn calls CheckForDisconnect to update the IOHandler status and reads data from the data source for the IOHandler connection.

ReadLn will return an empty string ('') if the peer connection is prematurely closed or a time-out occurs. If a timeout condition occurs in ReadLn, the ReadLnTimedOut property is set to True.

ReadLn can raise an EIdReadLnMaxLineLengthExceeded exception when the position of the end-of-line sequnce in the InputBuffer is greater than the maximum line length allowed for an IOHandler using the value maException in MaxLineAction.

All ATerminator characters in the return value for ReadLn (including CR and LF characters) are removed prior to exiting from the method.
Zitat von Jamah:
Und:
Was mache ich, wenn ich nicht aus dem Kontext sondern aus irgendeiner Prozedur eine Rückgabe brauche?
Wenn Du es nicht aus dem Context heraus etwas schicken willst,
dann mußt Du die ThreadListe des Servers durchgehen und den Clients die in der Liste stehen
etwas schicken. (Oder Du führtst selber eine Liste und nutzt diese).
Delphi-Quellcode:
procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
begin
  IdTCPServer1.Active:= True;
  ListBox1.Items.Add(split(AContext.Connection.IOHandler.ReadLn(),'|',1));
end;
Es ist etwas ungeschickt, den Sever im onExecute zu aktivieren.
Wäre der Server da nicht schon bereits aktiviert würde das onExecute auch
nicht ausgelöst werden.

Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat