fscom.bufferedstream: | Types | Modinfo | Source |
TBufferedStream | This is the TBufferedStream type. |
Type TBufferedStream Extends TStream | |
Description | This is the TBufferedStream type. |
Information | Connect a socket to a buffered stream with one of the three constuctors. A buffered stream has a receive buffer and a send buffer.
Recv will fill the receive buffer with data from the socket if available, Send will send the contents of the send buffer and will empty it. Use the methods of TStream to read from the receive buffer and write to the send buffer. Use the RecvFrom and SendTo methods to manage a UDP server socket. |
Constants Summary | |
---|---|
FLAG_AUTO_CLOSE , FLAG_RECV_ON_EOF , FLAG_SEND_ON_FLUSH |
Methods Summary | |
---|---|
Eof | Get stream end of file status. |
ReadAvail | Returns the of available bytes from the socket. |
Recv | Receives all available data. |
RecvFrom | Receives available data from a remote host. |
Send | Sends the buffered data. |
SendTo | Connects the socket to the given ip and port and sends the buffered data. |
Functions Summary | |
---|---|
Create | Socket Constructor. |
CreateTCPClient | TCP Client Constructor. |
CreateUDPClient | UDP Client Constructor. |
Const FLAG_AUTO_CLOSE:Byte | |
Description | Close the socket if the stream is closed. |
Const FLAG_RECV_ON_EOF:Byte | |
Description | Call Recv if the buffer is empty and any read-action should be performed or Eof is called. |
Const FLAG_SEND_ON_FLUSH:Byte | |
Description | Call Send if Flush is called. |
Method Eof:Int() | |
Returns | -1, 0, or 1. |
Description | Get stream end of file status. |
Information | The behavior differs slightly from the recommended in BRL.Stream:
* 0 will be returned if there is something in the receive buffer or the server is connected
* 1 will be returned if there is nothing more to read and the server is not connected anymore
* -1 will be returned if there is nothing to read but the server is still connected.
So classic "While Not stream.Eof()"-loops will only run if there is something to read in the buffer. This method will call Recv if FLAG_RECV_ON_EOF is set and the receive buffer is empty. |
Method ReadAvail:Int() | |
Description | Returns the of available bytes from the socket. |
Information | Call Recv or RecvFrom to read the available data into the internal buffer. |
Method Recv:Int() | |
Returns | the number of bytes read. |
Description | Receives all available data. |
Information | This method will check the sockets ReadAvail and tries to read everything from the socket. |
Method RecvFrom:Int(ip:Int Var , port:Int Var) | |
Returns | the number of bytes read. |
Description | Receives available data from a remote host. |
Information | This method will check the sockets ReadAvail and tries to read everything from the socket. However it will only read messages from one host and must be called again to read a message from another host. The host the message is from can be retrieved by the ip and port variables. This method is useful for UDP-Server-Streams. |
Method Send:Int() | |
Returns | The number of bytes sent. |
Description | Sends the buffered data. |
Method SendTo:Int(ip:Int , port:Int) | |
Returns | The number of bytes sent. |
Description | Connects the socket to the given ip and port and sends the buffered data. |
Information | This method is useful for UDP-Server-Streams. |
Function Create:TBufferedStream(socket:TSocket,flags:Byte=FLAG_AUTO_CLOSE|FLAG_SEND_ON_FLUSH|FLAG_RECV_ON_EOF) | |
Description | Socket Constructor. |
Information | Wraps a TBufferedStream around an existing socket. flags can be a combination of FLAG_AUTO_CLOSE, FLAG_SEND_ON_FLUSH and FLAG_RECV_ON_EOF Combination of all flags allowes you to use the TBufferedStream as a TStream without using the underlying socket or any methods defined by TBufferedStream. |
Function CreateTCPClient:TBufferedStream( remoteHost:String,remotePort:Int,flags:Byte=FLAG_AUTO_CLOSE|FLAG_SEND_ON_FLUSH|FLAG_RECV_ON_EOF ) | |
Description | TCP Client Constructor. |
Information | Will create a TCP socket and connect it to the given host and port, then calls Create with the given flags. It's not recommended to switch off the FLAG_AUTO_CLOSE with this method. |
Function CreateUDPClient:TBufferedStream( remoteHost:String,remotePort:Int,flags:Byte=FLAG_AUTO_CLOSE|FLAG_SEND_ON_FLUSH|FLAG_RECV_ON_EOF) | |
Description | UDP Client Constructor. |
Information | Will create a UDP socket and connect it to the given host and port, then calls Create with the given flags. It's not recommended to switch off the FLAG_AUTO_CLOSE with this method. |
Version | 0.3 |
---|---|
Author | Francesco Silvani |
License | zlib/libpng |
History | 0.3 |
History | TODO Fixed Read |
History | 0.2 |
History | Changed Eof so if the buffer is not empty, it will always return false. |