Difference between revisions of "TWSocket.LineMode"

From Overbyte
Jump to navigation Jump to search
(example added)
 
(3 intermediate revisions by 2 users not shown)
Line 11: Line 11:
 
== Example ==
 
== Example ==
  
If the client always sends data lines which end on CR/LF and the server shall display the lines individually in a memo, the server would set LineMode to true so that he always receives whole lines without needing to look for the end of a line himself.
+
If the client always sends data lines terminated with CR/LF and the server shall display the lines individually in a memo, the server would set LineMode to true so the caller always receives complete lines without needing to search for the end of line.
  
 +
<syntaxhighlight lang="delphi">
 
   Socket.LineLimit:=100;            // prevent denial of service or buffer  
 
   Socket.LineLimit:=100;            // prevent denial of service or buffer  
 
                                     // overflows
 
                                     // overflows
   Socket.LineEnd :=chr(10)+chr(13); // the sender has to terminate all  
+
   Socket.LineEnd:=chr(10) + chr(13); // the sender has to terminate all  
 
                                     // messages sent with this character  
 
                                     // messages sent with this character  
 
                                     // combination
 
                                     // combination
 
   Socket.LineMode:=true;
 
   Socket.LineMode:=true;
 +
</syntaxhighlight>
  
 
In [[TWSocket.OnDataAvailable|OnDataAvailable]] ReceiveStr is used to fetch the available data packet by packet.
 
In [[TWSocket.OnDataAvailable|OnDataAvailable]] ReceiveStr is used to fetch the available data packet by packet.
  
 
== Best practices ==
 
== Best practices ==
 +
Always set LineLimit to prevent buffer overflows.
  
 
== How to ==
 
== How to ==

Latest revision as of 00:49, 10 March 2016

Main page -> ICS component reference -> TWSocket -> LineMode

Definition

property LineMode: boolean;

Description

If set to true, LineMode enables automatic splitting of received data into packets based on a user definable char sequence.

Example

If the client always sends data lines terminated with CR/LF and the server shall display the lines individually in a memo, the server would set LineMode to true so the caller always receives complete lines without needing to search for the end of line.

<syntaxhighlight lang="delphi">

 Socket.LineLimit:=100;             // prevent denial of service or buffer 
                                    // overflows
 Socket.LineEnd:=chr(10) + chr(13); // the sender has to terminate all 
                                    // messages sent with this character 
                                    // combination
 Socket.LineMode:=true;

</syntaxhighlight>

In OnDataAvailable ReceiveStr is used to fetch the available data packet by packet.

Best practices

Always set LineLimit to prevent buffer overflows.

How to