Class TNetCom
Unit
PXL.NetComs
Declaration
type TNetCom = class(TObject)
Description
A simple communication component that can transmit and receive messages through UDP protocol over local network and/or Internet.
Hierarchy
Overview
Internal Types
 |
TReceiveEvent = procedure(const Sender: TObject; const Host: StdString; const Port: Integer; const Data: Pointer; const Size: Integer) of object; |
Methods
Properties
Description
Internal Types
 |
TReceiveEvent = procedure(const Sender: TObject; const Host: StdString; const Port: Integer; const Data: Pointer; const Size: Integer) of object; |
|
Data reception event. In this event the incoming message should be interpreted and properly handled. After this event executes, memory referenced by provided pointers is lost; therefore, to preserve the message it is necessary to copy it somewhere within this event. Source host and port can be used to identify the receiver and for sending replies.
Parameters
- Sender
- Reference to the class that received the message, usually TNetCom.
- Host
- Source host that sent the message.
- Port
- Source port through which the message was sent.
- Data
- Pointer to the beginning of message block.
- Size
- Size of the message block.
|
Methods
 |
function Initialize: Boolean; |
|
Initializes the component and begins listening to the given port for incoming messages. LocalPort should be set before calling this function to set a specific listening port. If LocalPort remains zero before this call, the listening port will be selected by the system from among available ones and LocalPort will be updated to reflect this. True is returned when the operation was successful and False otherwise.
|
 |
function ResolveHost(const Host: StdString): StdString; |
|
Converts text containing host address into the corresponding IP address.
|
 |
function ResolveIP(const IPAddress: StdString): StdString; |
|
Converts text containing IP address into the corresponding host string.
|
 |
function Send(const Host: StdString; const Port: Integer; const Data: Pointer; const Size: Integer): Boolean; |
|
Sends the specified message data block to the destination.
Parameters
- Host
- Destination host or address where the message should be sent. Multicast and broadcast addresses are accepted, although should be used with care to not saturate the local network.
- Port
- Destination port where the receiver is currently listening at.
- Data
- Pointer to the message data block. The method copies the data to its internal structures, so it's not necessary to maintain the buffer after this call exits.
- Size
- Size of the message data block.
Returns
True when the packet was sent successfully and False when there were errors. It is important to note that since messages are sent through UDP protocol, True return value doesn't necessarily mean that the packet was actually received.
|
 |
procedure Finalize; |
|
Finalizes the component and closes the communication link.
|
 |
procedure ResetStatistics; |
|
Resets all statistic parameters related to the current session such as number of packets transmitted, bytes per second among others.
|
 |
procedure Update; |
|
Handles internal communication and receives incoming messages; in addition, internal structures and bandwidth usage are also updated. This method should be called as fast as possible and no less than once per second. During the call to this method, OnReceive event may occur to notify the reception of messages.
|
Properties
 |
property Broadcast: Boolean read FBroadcast write SetBroadcast; |
|
Determines whether the communication should support broadcast and multicast messages. This can be written to only before the component is initialized, but can be read from at any time.
|
 |
property BytesPerSec: Integer read FBytesPerSec; |
|
Indicates the current bandwidth usage in bytes per second. In order for this variable to have meaningful values, it is necessary to call Update method at least once per second.
|
 |
property BytesReceived: Integer read FBytesReceived; |
|
Indicates how many bytes were received during the entire session.
|
 |
property BytesSent: Integer read FBytesSent; |
|
Indicates how many bytes were sent during the entire session.
|
 |
property Initialized: Boolean read FInitialized; |
|
Indicates whether the component has been properly initialized.
|
 |
property LocalIP: StdString read GetLocalIP; |
|
Returns IP address of current machine. If several IP addresses are present, the last address in the list is returned.
|
 |
property LocalPort: Integer read FLocalPort write SetLocalPort; |
|
Local port that is used for listening and transmitting packets. This can be written to only before the component is initialized, but can be read from at any time.
|
 |
property OnReceive: TReceiveEvent read FOnReceive write FOnReceive; |
|
This event occurs when the data has been received. It should always be assigned to interpret any incoming messages.
|
 |
property ReceivedPackets: Integer read FReceivedPackets; |
|
Indicates how many packets in total were received during the entire session.
|
 |
property SentPackets: Integer read FSentPackets; |
|
Indicates how many packets were sent during the entire session.
|
 |
property UpdateRefreshTime: Integer read FUpdateRefreshTime write SetUpdateRefreshTime; |
|
Time interval (in milliseconds) to consider for "BytesPerSec" calculation.
|
Copyright © 2000 - 2017 Yuriy Kotsarenko. Help files generated by PasDoc.
|