fscom.bufferedstream: Types Modinfo Source  

Bufferedstream - A brl.socketstream replacement

Types Summary

TBufferedStream This is the TBufferedStream type.

Types

Type TBufferedStream Extends TStream
DescriptionThis is the TBufferedStream type.
InformationConnect 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
DescriptionClose the socket if the stream is closed.
Const FLAG_RECV_ON_EOF:Byte
DescriptionCall Recv if the buffer is empty and any read-action should be performed or Eof is called.
Const FLAG_SEND_ON_FLUSH:Byte
DescriptionCall Send if Flush is called.
Method Eof:Int()
Returns-1, 0, or 1.
DescriptionGet stream end of file status.
InformationThe 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()
DescriptionReturns the of available bytes from the socket.
InformationCall Recv or RecvFrom to read the available data into the internal buffer.
Method Recv:Int()
Returnsthe number of bytes read.
DescriptionReceives all available data.
InformationThis method will check the sockets ReadAvail and tries to read everything from the socket.
Method RecvFrom:Int(ip:Int Var , port:Int Var)
Returnsthe number of bytes read.
DescriptionReceives available data from a remote host.
InformationThis 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()
ReturnsThe number of bytes sent.
DescriptionSends the buffered data.
Method SendTo:Int(ip:Int , port:Int)
ReturnsThe number of bytes sent.
DescriptionConnects the socket to the given ip and port and sends the buffered data.
InformationThis 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)
DescriptionSocket Constructor.
InformationWraps 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 )
DescriptionTCP Client Constructor.
InformationWill 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)
DescriptionUDP Client Constructor.
InformationWill 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.

Module Information

Version0.3
AuthorFrancesco Silvani
Licensezlib/libpng
History0.3
HistoryTODO Fixed Read
History0.2
HistoryChanged Eof so if the buffer is not empty, it will always return false.