Difference between revisions of "Glossary"
m (→Delimited Data) |
|||
Line 10: | Line 10: | ||
===Delimited Data=== | ===Delimited Data=== | ||
− | Sender and receiver must agree on how to transfer data. In a TCP session, imagine a sender sends two strings "Hello" and "LogMeIn" one after another. How to make sure that they will be received also one after another as two separate strings? Most likely they will be received by winsock as one string like "HelloLogMeIn", winsock then notifies the application about data has been received and is available. As you can see the receiver needs some more information, either some delimiter is required in order to allow the receiver to split up data back into its original parts or the length of each part must be prepended. The easiest way however is to use a delimiter. Many line-based internet protocols such as SMTP simply use CRLF for this purpose. ICS provides properties and methods to easily send and receive such delimited data. Properties LineMode and LineEnd as well as method ReceiveStr. If you turn on LineMode event OnDataAvailable will fire only in case of the delimiter specified in property LineEnd has been received. In order to read such delimited data from within OnDataAvailable event handler you may simply call method ReceiveStr, that's it. OnDataAvailable would fire exactly twice and each call to ReceiveStr would return the correct strings "Hello" and "LogMeIn". But note that the sender must append the delimiter to each string | + | Sender and receiver must agree on how to transfer data. In a TCP session, imagine a sender sends two strings "Hello" and "LogMeIn" one after another. How to make sure that they will be received also one after another as two separate strings? Most likely they will be received by winsock as one string like "HelloLogMeIn", winsock then notifies the application about data has been received and is available. As you can see the receiver needs some more information, either some delimiter is required in order to allow the receiver to split up data back into its original parts or the length of each part must be prepended. The easiest way however is to use a delimiter. Many line-based internet protocols such as SMTP simply use CRLF for this purpose. ICS provides properties and methods to easily send and receive such delimited data. Properties LineMode and LineEnd as well as method ReceiveStr. If you turn on LineMode event OnDataAvailable will fire only in case of the delimiter specified in property LineEnd has been received. In order to read such delimited data from within OnDataAvailable event handler you may simply call method ReceiveStr, that's it. OnDataAvailable would fire exactly twice and each call to ReceiveStr would return the correct strings "Hello" and "LogMeIn". But note that the sender must append the delimiter to each string explicitly. To send delimited data you may use method SendStr, for instance SendStr('Hello' + #13#10). |
==E== | ==E== |
Revision as of 08:53, 22 February 2006
Contents
A
B
C
D
Delimited Data
Sender and receiver must agree on how to transfer data. In a TCP session, imagine a sender sends two strings "Hello" and "LogMeIn" one after another. How to make sure that they will be received also one after another as two separate strings? Most likely they will be received by winsock as one string like "HelloLogMeIn", winsock then notifies the application about data has been received and is available. As you can see the receiver needs some more information, either some delimiter is required in order to allow the receiver to split up data back into its original parts or the length of each part must be prepended. The easiest way however is to use a delimiter. Many line-based internet protocols such as SMTP simply use CRLF for this purpose. ICS provides properties and methods to easily send and receive such delimited data. Properties LineMode and LineEnd as well as method ReceiveStr. If you turn on LineMode event OnDataAvailable will fire only in case of the delimiter specified in property LineEnd has been received. In order to read such delimited data from within OnDataAvailable event handler you may simply call method ReceiveStr, that's it. OnDataAvailable would fire exactly twice and each call to ReceiveStr would return the correct strings "Hello" and "LogMeIn". But note that the sender must append the delimiter to each string explicitly. To send delimited data you may use method SendStr, for instance SendStr('Hello' + #13#10).
E
F
G
H
I
J
K
L
Line Mode
Property LineMode specifies how TWSocket component shall trigger the OnDataAvailable event upon incomming data packets. If line mode is off (the default), TWSocket will trigger an OnDataAvailable event for each incomming data packet. If line mode is on (LineMode is set to TRUE), then TWSocket will buffer incomming data packets and search for an end-of-line marker specified by property LineEnd (defaults to CR/LF pair). If no end-of-line marker is found, the received packet is kept in the internal buffer and no OnDataAvailable event is triggered. When the next data packet is received, another check is done to find the first end-of- line. If it is found, the component triggers the OnDataAvailable event. When the Receive method is called from the OnDataAvailable event, it will return data up to and including the first end-of-line marker. If a second one is received, another OnDataAvailable will be triggered immediately. The advantage of using LineMode is that component users must not worry about packet fragmentation since they see data comming in line by line.