Monkey Documentation

Class NetworkEngine

A NetworkEngine acts as your connection or "node" in the network. More...


Extends:
Implements:
Constants:
  • Default_ClientMessagesAfterDisconnect : Bool
  • Default_FixByteOrder : Bool
  • Default_MaxChunksPerMegaPacket : Int
  • Default_MaxPing : NetworkPing
  • Default_MegaPacketTimeout : Duration
  • Default_MultiConnection : Bool
  • Default_PacketPoolSize : Int
  • Default_PacketReleaseTime : Duration
  • Default_PacketResendTime : Duration
  • Default_PacketSize : Int
  • Default_PingFrequency : Duration
  • MEGA_PACKET_TIMEOUT_NONE : Int
  • PORT_AUTOMATIC : Int
  • SOCKET_TYPE_TCP : ProtocolType
  • SOCKET_TYPE_UDP : ProtocolType
Fields:
Constructors:
  • New ( PacketSize:Int=default_packetsize, PacketPoolSize:Int=default_packetpoolsize, FixByteOrder:Bool=default_fixbyteorder, PingFrequency:Duration=default_pingfrequency, MaxPing:NetworkPing=default_maxping, MaxChunksPerMegaPacket:Int=default_maxchunkspermegapacket, PacketReleaseTime:Duration=default_packetreleasetime, PacketResendTime:Duration=default_packetresendtime, MegaPacketTimeout:Duration=default_megapackettimeout )
Properties:
Methods:
Functions:
Inherited Methods:
Inherited Functions:

Detailed Discussion

A NetworkEngine acts as your connection or "node" in the network. At present, a NetworkEngine can be a client or a host. These documents regard "nodes" as abstract entry-points to the network. In other words, clients or hosts, or potentially actual nodes (Peer-to-peer will eventually be looked into).

NetworkEngine objects handle incoming and outgoing messages, client connections, notifications via the "NetworkListener" interfaces, just the protocol in general. They require your application to continually use the official asynchronous call-back routine, UpdateAsyncEvents. The entire framework works using asynchrnous routines, meaning it's portable across targets. There are several situations where asynchronous techniques can be user-defined, but this framework reserves the right to ignore these requests if necessary.

NetworkEngine objects handle the vast majority of what goes on behind the scenes, and they are responsible for the objects they emit. That being said, if an object is allocated via a pool, or similar system, it's up to the user to return the object(s) provided.

Though undocumented, most BRL Socket asynchronous callbacks are implemented, and can be extended when extending this framework. That being said, this framework reserves the right to resolve "Socket" as any type it sees fit. The documentation currently only reflects the BRL implementation.


Field Documentation

Field ClientCallback : ClientNetworkListener

This field is protected.

Field ClientMessagesAfterDisconnect : Bool

This specifies if normal messages should be accepted after a client has been told to disconnect.

Field Clients : List<Client>

A collection of connected Client handles. For clients, the first entry is Remote.

This field is protected.

Field Connection : Socket

This acts as the primary connection-socket. This is what all network operations are done with when using UDP; and what client acceptance is done with when using TCP.

This field is protected. To access this externally, use Socket (Use at your own risk).

Field CoreCallback : CoreNetworkListener

This field is protected.

Field MaxChunksPerMegaPacket : Int

This represents the maximum number of "mega-packet" chunks allowed. Chunk sizes depend on 'PacketSize' on the other end.

In other words, this is variable, but it should never be larger than the other side's PacketSize.

Field MaxPing : NetworkPing

This is the maximum ping a Client can have before being released.

Field MegaPacketCallback : MegaPacketNetworkListener

This field is protected.

Field MegaPacketTimeout : Duration

This stores the amount of time a 'MegaPacket' is allowed to idle.

Field MetaCallback : MetaNetworkListener

This field is protected.

Field PacketReleaseTime : Duration

This stores the amount of time it takes to forget a packet ID.

Field PacketResendTime : Duration

This stores the amount of time between reliable-packet re-sends.

Field PendingMegaPackets : Stack<MegaPacket>

This is a container of pending (Local; outbound) MegaPacket objects.

This field is protected.

Field PingFrequency : Duration

This stores the minimum amount of time between ping-detections.

Field ReliablePackets : Stack<ReliablePacket>

This is a container representing reliable packets in transit.

For more information on reliable packets, and how they work, see AllocateReliablePacket and ReliablePacket.

This field is protected.

Field SystemPackets : Stack<Packet>

This is a container of packets allocated to the internal system.

For more information on "system packets", see AddSystemPacket.

This field is protected.


Constructor Documentation

Method New ( PacketSize:Int=default_packetsize, PacketPoolSize:Int=default_packetpoolsize, FixByteOrder:Bool=default_fixbyteorder, PingFrequency:Duration=default_pingfrequency, MaxPing:NetworkPing=default_maxping, MaxChunksPerMegaPacket:Int=default_maxchunkspermegapacket, PacketReleaseTime:Duration=default_packetreleasetime, PacketResendTime:Duration=default_packetresendtime, MegaPacketTimeout:Duration=default_megapackettimeout )

  • The PacketSize argument specifies the size used for all internally allocated packets.
  • The PacketPoolSize argument is used to generate initial packet-objects.
  • The FixByteOrder argument toggles network byte-order for internally generated packets.
  • The PingFrequency argument is used to determine how much time it takes between ping calculations.
  • The MaxPing argument is used when determining if a Client has timed out.
  • The MaxChunksPerMegaPacket argument is used to limit the number of Packet objects an incoming MegaPacket can be initialized with.
  • The PacketReleaseTime argument is used to describe how long it takes for a Client to remove the next reliable packet's PacketID. (UDP / unreliable transport protocols)
  • The PacketResendTime argument specifies how long it takes for this network to resend a ReliablePacket.
  • The MegaPacketTimeout argument states how long a remote MegaPacket handle can idle before being terminated.


Property Documentation

Method BigEndian : Bool () Property

This is a proxy to an internal BasicPacketPool object's FixByteOrder property. This corresponds to the 'FixByteOrder' constructor argument.

Method Bound : Bool () Property

This states if Socket/Connection has been bound. If the network is closed, this will always return False.

See also: Closed, Close

Method ClientCount : Int () Property

This counts the number of Clients who are connected to this network, and are not closing/disconnecting.

Method Closed : Bool () Property

This states if the network is closed.

Please check for open-status with Open instead of this. Opening networks aren't closed, but they aren't open either. And closing/terminating networks are open, but they aren't closed yet.

See also: Open, Close, CloseAsync

Method HasCallback : Bool () Property

This specifies if this network has at least one callback.

Method HasClient : Bool () Property

This indicates if there is at least one Client in this network that is not closing/disconnecting.

This always reports True for clients, as Remote will report a Client representing the remote host.

Method HasClientCallback : Bool () Property

This specifies if ClientCallback is available.

Method HasCoreCallback : Bool () Property

This specifies if CoreCallback is available.

Method HasDisconnectingClient : Bool () Property

This indicates if there is at least one Client in this network that is closing/disconnecting.

Method HasMegaPacketCallback : Bool () Property

This specifies if MegaPacketCallback is available.

Method HasMetaCallback : Bool () Property

This specifies if MetaCallback is available.

Method IsClient : Bool () Property

This states if this is a "client network". (True if started via Connect)

This property has protected assignment-access.

Method MultiConnection : Bool () Property

This corresponds with the constructor argument of the same name. Basically, this dictates whether more than one (Client) connection is allowed.

This property has protected assignment-access.

Method Open : Bool () Property

This will return True if Closed is False, and Connection/Socket is bound.

See also: Closed, Host, Connect, Close, CloseAsync

Method PacketSize : Int () Property

This is a proxy to an internal BasicPacketPool object's PacketSize property. This corresponds to the constructor argument of the same name.

Method RawClientCount : Int () Property

This counts the number of Client handles in the Clients container, without caring about their closing status.

Method Remote : Client () Property

This represents the remote 'host-node' for clients. For hosts, this always reports Null.

Method Socket : Socket () Property

This is used to delegate the Connection field. When writing code to extend an engine, don't use this property. Everywhere else (External systems / public extension), use this.

See also: Connection

Method SocketType : ProtocolType () Property

This represents the transport protocol used by the network.

This property has protected assignment-access.

See also: ProtocolToString

Method TCPSocket : Bool () Property

This returns True if SocketType reports SOCKET_TYPE_TCP.

Method Terminating : Bool () Property

This states if this network is being terminated. (Closing "asynchronously")

This property has protected assignment-access.

Method UDPSocket : Bool () Property

This returns True if SocketType reports SOCKET_TYPE_UDP.


Method Documentation

Method AbortMegaPacket : Void ( C:Client, ID:PacketID, Reason:PacketExtResponse=mega_packet_response_abort )

This sends a rejection message regarding a remote MegaPacket with ID, to C with Reason.

In addition to rejecting the MegaPacket, this will call RemoveWaitingMegaPacket on C.

This method is protected.

See also: SendMegaPacketRejection, RemovePendingMegaPacket, GetWaitingMegaPacket

Method AbortMegaPacket : Void ( MP:MegaPacket, FromClient:Bool, Reason:PacketExtResponse=mega_packet_response_abort )

This aborts a MegaPacket, either through a Client, or locally via RemovePendingMegaPacket.

This depends on the FromClient argument, which is used for the protocol, and for proper cleanup.

This method is protected.

See also: SendMegaPacketRejection, RemovePendingMegaPacket, GetWaitingMegaPacket

Method AddPendingMegaPacket : Void ( MP:MegaPacket )

This adds MP as a local MegaPacket internally. Basically, MP will be held in a container, so it can be referenced by the receiving end using its ID.

This method is protected.

See also: RemovePendingMegaPacket, GetPendingMegaPacket

Method AddSystemPacket : Void ( P:Packet )

This is used to manually add a "system packet".

"System packets" are automatically managed Packet objects, that are held for later attainment when their underlying buffer is sent back through an internal callback.

For example, the packet-less overloads for the "LaunchAsync" and "AutoLaunch" internal methods allocate system packets.

If unsure, don't mess with this.

This method is protected.

See also: AllocateSystemPacket, DeallocateSystemPacket, RemoveSystemPacket

Method AllocateMegaPacket : MegaPacket ()

This will allocate a MegaPacket object for use within this network.

When finished with this object, please call ReleaseMegaPacket. (Sending does not release a MegaPacket formally)

Method AllocatePacket : Packet ()

This allocates and initializes a Packet object for general use, usually from a pool.

This object can be used to read (Requires extension) or write messages. Once finished, you can call Send, or AutoSendRaw, depending on your use-case.

Because this is likely from a pool, please call ReleasePacket when finished with the Packet object you get from this.

Method AllocateReliablePacket : ReliablePacket ( Destination:Client, ID:PacketID )

This allocates an internal ReliablePacket object as a "system packet".

This is used internally, and should only be messed with if you completely understand it.

ReliablePacket objects are not relevant to reliable transport protocols, like TCP.

If unsure, don't mess with this.

This method is protected.

See also: DeallocateReliablePacket

Method AllocateReliablePacket : ReliablePacket ( Destination:Client )

Like the main overload, this will allocate a ReliablePacket as a "system packet".

Unlike that overload, this will call GetNextReliablePacketID for the packet's reliable identifier (PacketID).

If unsure, don't mess with this.

This method is protected.

See also: DeallocateReliablePacket

Method AllocateRemoteMegaPacket : MegaPacket ( ID:PacketID, Destination:Client=null )

This allocates a MegaPacket object for remote representation.

This does not hold the returned object internally, please call AddWaitingMegaPacket

This method is protected.

Method AllocateSystemPacket : Packet ()

This is used to allocate a "system packet".

Basically, this will call AllocatePacket, then add it as a "system packet" using AddSystemPacket.

For details on "system packets", please view the AddSystemPacket method's documentation.

If unsure, don't mess with this.

This method is protected.

Method AutoLaunchReceive : Void ( S:Socket, P:Packet, Force:Bool=false )

This is used to launch a technology-independent receival thread/operation, asynchronously. (Depends on underlying socket behavior)

S and P are used to perform this operation, and P will likely be reintegrated into this engine when operations are all finished. In other words, assume P is the property of this network.

Assume Force as an unsafe argument; used internally.

This method is protected.

Method AutoLaunchReceive : Void ( S:Socket, Force:Bool=false )

This works like the main implementation. The only difference being, this will allocate a Packet object automatically, and handle its deconstruction/storage.

Assume Force as an unsafe argument; used internally.

This routine does not work with WebSockets.

This method is protected.

Method AutoReleaseWaitingMegaPacket : Void ( MP:MegaPacket )

This calls ReleaseWaitingMegaPacket with MP, and uses its Destination instead of an exact Client object provided by the user.

For details on method-behavior, please view that implementation's documentation.

This method is protected.

See also: AllocateMegaPacket, ReleaseWaitingMegaPacket, RemoveWaitingMegaPacket, ReleaseInternalMegaPacket

Method AutoSendRaw : Void ( RawPacket:Packet, Async:Bool=true )

Use this method at your own risk.

This is used to send a raw packet, unlike Send, which builds a formatted raw packet around the described packet. This doesn't handle formats, it simply sends RawPacket to the default destination. (Clients to host, host to clients) The Async argument is used to toggle asynchronous output; queued, could be slower.

See also: Send

Method AutoSendRaw : Void ( RawPacket:Packet, C:Client, Async:Bool=true )

Use this method at your own risk.

This is used to send a raw packet, unlike Send, which builds a formatted raw packet around the described packet. This doesn't handle formats, it simply sends RawPacket to the described destination (C). (Clients must send to hosts, hosts can send to any client) The Async argument is used to toggle asynchronous output; queued, could be slower.

See also: Send

Method Bind : Bool ( Connection:Socket, Port:Int, Async:Bool=false, Hostname:String="" )

This will bind Connection, using this network.

If Async is disabled, this will return whether the bind operation was successful.

If enabled, this will only return False when an internal error occurs.

Binding is done for UDP hosts, mainly. TCP and UDP clients use "automated connection". This can be done with RawConnect.

This method is protected.

See also: Host, RawConnect

Method Bind : Bool ( Port:Int, Async:Bool=false, Hostname:String="" )

This will use the internal socket to perform a bind operation.

This is used for UDP hosts. For details, see the main overload.

This method is protected.

See also: Host, RawConnect

Method BuildOutputMessage : Packet ( P:Packet, Type:MessageType, ExtendedPacket:Bool=false, DefaultSize:Int=0 )

Used internally; use at your own risk.

This command produces a packet in the appropriate format. This will generate a "system packet", which is handled internally. For details on the DefaultSize' argument, please see WriteMessage.

Internal messages do not serialize their data-segments' lengths.

Method BuildReliableMessage : Void ( Data:Packet, Type:MessageType, RP:ReliablePacket, ExtendedPacket:Bool=false )

Used internally; use at your own risk.

This will take the contents of Data, transfer it to RP, as well as write any needed formatting. This allows you to use RP as a normal system-managed packet.

ReliablePacket objects should not be used by TCP networks.

See also: BuildOutputMessage

Method BuildReliableMessage : ReliablePacket ( Data:Packet, Type:MessageType, C:Client, ExtendedPacket:Bool=false )

This will generate a ReliablePacket automatically, then call the primary implementation; the same restrictions apply.

See also: BuildOutputMessage

Method Close : Void ()

This command manually closes this network.

The network will automatically send remote connections a final unreliable message describing this action. In the case of TCP (Or similar; reliable transport), this will very likely make it to the other end, disconnecting very gracefully.

When using UDP, this message is somewhat unlikely to make it to the destination(s).

If this description message (INTERNAL_MSG_DISCONNECT) is not received, this client/host will timeout on the other end(s). This means that disconnection will happen regardless, but the elegance of this action is unlikely to be preserved. (Transport differences aside)

To disconnect via a request, and in worst case scenarios, a timeout, use CloseAsync. (Ideal)

Method CloseAsync : Void ()

This command provides a means of gracefully disconnecting from a remote network. To manually disconnect from a network, use Close.

For clients, this is done through a reliable disconnection notice (INTERNAL_MSG_REQUEST_DISCONNECTION), and assuming closing status. The notice will be sent, then the usual behavior of Closing will be applied; limited message acceptance, eventual timeout/disconnection, etc. Ideally, we'd get a message back, and from there, automatically call Close.

For hosts, this will disconnect every client formally. It will then use the Terminating flag to check if all clients have disconnected. Once they have, the Close command will be called automatically.

Method ConfirmReliablePacket : Bool ( C:Client, ID:PacketID )

This is used internally to automate the process of confirming a reliable packet. This routine is only valid when using unreliable transport protocols, like UDP.

This method is protected.

Method Connect : Bool ( Address:NetworkAddress, Async:Bool=false, Protocol:ProtocolType=socket_type_udp )

This is used to create a client network using Address with Protocol. Once a connection has been established, please call Update regularly. When you intend to end the network-session, please call Close or CloseAsync.

  • The Address argument is used to connect to a remote NetworkEngine.
  • The Async argument specifies if connection should be done asynchronously. (May be required on some targets)
  • The Protocol argument describes the desired transport protocol.
See also: Host, Close, CloseAsync

Method Connect : Bool ( Host:String, Port:Int, Async:Bool=false, Protocol:ProtocolType=socket_type_udp )

This generates a NetworkAddress object from Host and Port, then calls the main implementation using the arguments specified.

See also: Host, Close, CloseAsync

Method Connected : Bool ( S:Socket )

This returns True if a Client with S as its socket was found.

This is only useful for TCP; UDP always returns False.

See also: GetClient

Method Connected : Bool ( Address:NetworkAddress )

This returns True if a Client with Address as its Address was found.

See also: GetClient

Method DeallocateReliablePacket : Bool ( RP:ReliablePacket )

This performs a formal deallocation of RP, including "system packet" management.

The return-value indicates if RP was released to this network. If False, something else is using this object. In this situation, ignore RP, as it isn't relevant to your code anymore.

RP should only be an object previously allocated with AllocateReliablePacket.

For details, view the documentation for that method, and AddSystemPacket.

If unsure, don't mess with this.

This method is protected.

See also: AllocateReliablePacket, ReleaseReliablePacket

Method DeallocateSystemPacket : Bool ( P:Packet )

This will remove all traces of a "system packet" allocated as one. In addition, this will handle reliable packet symantics if necessary.

The return-value of this command specifies if P is no longer in use, and has been removed. (True if everything worked, and it's now in the main "packet pool")

For details on "system packets", please view the AddSystemPacket and RemoveSystemPacket methods' documentation.

If unsure, don't mess with this.

This method is protected.

Method DeinitMegaPackets : Void ()

This deinitializes mega-packet functionality.

This destructor is protected.

See also: InitMegaPackets

Method DeinitReliablePackets : Void ()

This deinitializes reliable-packet functionality.

This destructor is protected.

See also: InitReliablePackets

Method Disconnect : Void ( C:Client )

This sends a reliable disconnection message to C, then marks C as Closing.

See also: DisconnectAll

Method DisconnectAll : Void ()

This disconnects every connected client from a host.

See also: Disconnect

Method ForceDisconnect : Void ( C:Client )

This force-releases C, sending an unreliable notification; use at your own risk.

Method GenerateNativeSocket : Void ( ProtocolString:String="stream" )

This is used internally to generate the internal connection-socket, and close if necessary.

This constructor is protected.

Method GetClient : Client ( Address:NetworkAddress )

This is used to retrieve a Client object using its address.

Do not keep a long-term handle to this object unless you intend to accept OnClientDisconnected notifications.

See also: ObjectEnumerator

Method GetClient : Client ( S:Socket )

Generally speaking, this should only be called when using TCP; for a general purpose routine, please use the overload accepting a NetworkAddress.

This retrieves a Client object using its socket. (Not recommended)

See also: ObjectEnumerator

Method GetNextMegaPacketID : PacketID ()

This may be used to retrieve the next mega-packet identifier. This will increment an internal ID-counter; use with caution.

This method is protected.

Method GetNextReliablePacketID : PacketID ()

This may be used to retrieve the next reliable-packet identifier. This will increment an internal ID-counter; use with caution.

This method is protected.

Method GetPendingMegaPacket : MegaPacket ( ID:PacketID )

This retrieves the MegaPacket object with ID, previously added with AddPendingMegaPacket.

If a MegaPacket couldn't be found, this will return Null.

This method is protected.

See also: AddPendingMegaPacket, RemovePendingMegaPacket

Method GetReliableHandle : ReliablePacket ( RawPacket:Packet )

This looks through our ReliablePacket objects still in play, and checks if one of them is actually RawPacket.

If unsure, don't mess with this.

This method is protected.

Method HasPendingMegaPacket : Bool ( ID:PacketID )

This returns True if a MegaPacket with the ID specified was found.

This method is protected.

See also: AddPendingMegaPacket, RemovePendingMegaPacket, GetPendingMegaPacket

Method Host : Bool ( Port:Int, Async:Bool=false, Protocol:ProtocolType=socket_type_udp, MultiConnection:Bool=default_multiconnection, Hostname:String="" )

This is used to host a network on Port using Protocol. Once hosting has started, please call Update regularly. When finished hosting, please call Close or CloseAsync.

  • The Port argument is used to bind the network-socket using Hostname.
  • The Async argument specifies if binding should be done asynchronously. (May be required on some targets)
  • The Protocol argument describes the desired transport protocol.
  • The MultiConnection argument dictates whether more than one connection is allowed.
  • The Hostname argument is used when binding the internal socket. (If unsure, do not specify)
The return value of this method states if hosting was successful. If Async is enabled, the return value will not indicate success, only initial failure. Success would be determined using OnNetworkBind.

See also: Connect, Close, CloseAsync

Method Init : Void ( Protocol:ProtocolType, IsClient:Bool )

This is a common internal "startup constructor", called whenever Connect or Host is called. This generates the internal socket via GenerateNativeSocket.

This constructor is protected.

Method InitMegaPackets : Void ()

This initializes mega-packet functionality.

This constructor is protected.

See also: DeinitMegaPackets

Method InitReliablePackets : Void ()

This initializes reliable-packet functionality. (Pooling, management, etc)

This constructor is protected.

See also: DeinitReliablePackets

Method IsCallback : Bool ( Callback:NetworkListener )

This specifies if Callback is in any way a callback internally.

Method IsReliablePacket : Bool ( RawPacket:Packet )

This wraps a call to RawPacket's IsReliable implementation.

This method is protected.

Method LaunchAsyncReceive : Void ( S:Socket, P:Packet )

This performs a raw receive operation using S. Where S is "connected" to another end exclusively.

This is a specialized version of AutoLaunchReceive, please use that instead.

This routine does not work with WebSockets.

This method is protected.

See also: AutoLaunchReceive, LaunchAsyncReceiveFrom

Method LaunchAsyncReceiveFrom : Void ( S:Socket, P:Packet, Address:NetworkAddress )

Like AutoLaunchReceive, this will initialize a raw receive operation.

This one in particular is for UDP sockets, mainly, and is address-based, using Address as an output object for whoever sends a message.


This routine does not work with WebSockets.


This is a specialized version of AutoLaunchReceive, please use that instead.

This method is protected.

See also: AutoLaunchReceive, LaunchAsyncReceive

Method LaunchAsyncReceiveFrom : Void ( S:Socket, P:Packet )

This will generate a new NetworkAddress, then call the main implementation. For details, please view that overload's documentation.

This routine does not work with WebSockets.

This method is protected.

See also: AutoLaunchReceive, LaunchAsyncReceive

Method ObjectEnumerator : list.Enumerator<Client> ()

This allows you to enumerate the connected Clients in this network.

For clients, this will only supply Remote, for hosts, this provides all connected Client handles.

Method RawConnect : Bool ( Connection:Socket, Host:String, Port:Int, Async:Bool=false )

This performs a raw-connect operation on Connection.

If Async is disabled, this will return whether the connection operation was successful.

Raw connections allow us to establish a transport-level connection, which then means we can apply normal authentication atop it.

This method is protected.

See also: Connect, Bind

Method RawConnect : Bool ( Host:String, Port:Int, Async:Bool=false )

This will use the internal socket to perform a raw connection operation.

This is used by both TCP and UDP clients (Currently). For details, see the main overload.

This method is protected.

See also: Connect, Bind

Method RawSend : Void ( Connection:Socket, RawPacket:Packet, Async:Bool=true )

This command is used to send completely raw data (RawPacket) when using a connected socket (Connection).

This can be useful, as you can generate an output packet yourself, then send it as you see fit. Use these commands with caution.

In general, you should avoid using this command directly, and instead use AutoSendRaw, as it covers output semantics properly.

This method is protected.

See also: AutoSendRaw, RawSendToAll, Send

Method RawSend : Void ( Connection:Socket, RawPacket:Packet, Address:NetworkAddress, Async:Bool=true )

This sends a completely raw packet (RawPacket) to Address, assuming the underlying transport method supports this. This works for (UDP) clients when Address is the same as Remote's Address.

In general, you should avoid using this command directly, and instead use AutoSendRaw, as it covers output semantics properly.

This only works properly with UDP sockets.

This method is protected.

See also: AutoSendRaw, RawSendToAll, Send

Method RawSendToAll : Void ( RawPacket:Packet, Async:Bool=true )

This command is used to send completely raw data (RawPacket) to every connected Client.

This is only especially useful for hosts; clients will send normally.

In general, you should avoid using this command directly, and instead use AutoSendRaw, as it covers output semantics properly.

This method is protected.

See also: AutoSendRaw, RawSend, Send

Method ReadExtendedPacketChunk : Bool ( P:Stream, C:Client, Type:MessageType, DataSize:Int, DataSegmentOrigin:Int )

This is used internally to receive chunks from "extended packets" (MegaPackets).

This is usually called by ReadMessage, and will call ReadMessageBody when the message is finished.

This method is protected.

See also: ReadMessage, ReadMessageBody

Method ReadMessage : MessageType ( P:Packet, Address:NetworkAddress, Source:Socket )

This is called whenever a raw packet is received from a remote node.

This routine handles most of the input portion of the network's protocol.

Basically, this handles everything but handling the standard data-segment of user-level packets. So, any "internal messages" we receive will be read and managed through this method.

  • The P argument represents the raw input stream of the other end's data.
  • The Address argument describes the address of the sender.
  • The Source argument represents the socket used to receive this message.

If you are using TCP as your underlying protocol, then Source will always be available.

This will catch any StreamError thrown by this routine, and any sub routines, unless running in a debug configuration.

This method is protected.

See also: ReadMessageBody, ReadExtendedPacketChunk

Method ReadMessageBody : Bool ( P:Stream, C:Client, Type:MessageType, DataSize:Int, Address:NetworkAddress )

This routine handles safety and callbacks for packet data-segments.

  • The P argument should be a safe-to-use Stream containing the data-segment of a raw packet, as described before being sent over with Send (Or similar).
  • The C argument should be a handle to the client responsible for this message (Sending end).
  • The Type argument should specify a correct user-level type, as described by the other end's usage of Send (Or similar).
  • The DataSize argument should describe the length of the data-segment the user will be reading.
  • The Address argument should provide the address of C (Or similar).

This method is protected.

See also: ReadMessage, ReadExtendedPacketChunk

Method ReadMessageBody : Void ( P:Stream, C:Client, Type:MessageType, DataSize:Int )

This is provided for convenience; calls the main implementation using C's Address property.

This method is protected.

Method ReleaseClient : Void ( C:Client, RemoveInternally:Bool=true )

This is used to manually release a Client from this network.

This will not disconnect the client, only call OnClientDisconnected, and remote it internally if RemoveInternally is enabled.

This method is protected.

See also: Disconnect, ForceDisconnect, DisconnectAll

Method ReleaseClient : Void ( S:Socket, RemoveInternally:Bool=true )

This should only be called when using TCP.

In addition, the S must be held by a Client.

This calls the main overload with a Client object holding S.

This method is protected.

See also: Disconnect, ForceDisconnect, DisconnectAll

Method ReleaseInternalMegaPacket : Bool ( MP:MegaPacket )

This releases an internally allocated MegaPacket object; will likely fail for externally allocated objects (Unsafe).

The return-value of this command dictates the release-status of MP.

This should only be called on an object allocated with AllocateMegaPacket.

This does not remove any references to MP.

This method is protected.

See also: AllocateMegaPacket

Method ReleaseMegaPacket : Void ( MP:MegaPacket )

This should only be called on an object allocated with AllocateMegaPacket.


If you're dealing with specialized MegaPackets (Protected routines), please call ReleasePendingMegaPacket (Or ReleaseWaitingMegaPacket).

Method ReleasePacket : Bool ( P:Packet )

This releases a Packet object allocated from AllocatePacket.

Passing an object that was not from AllocatePacket is considered "unsafe", and will result in undefined behavior.

The return-value of this method indicates if the object was accepted. For most cases, just call this without worrying about the return-value.

See also: AllocatePacket

Method ReleasePendingMegaPacket : Void ( MP:MegaPacket )

This removes MP (A pending/local MegaPacket) from an internal container, then releases it.

This automatically calls RemovePendingMegaPacket and ReleaseInternalMegaPacket

This method is protected.

See also: AllocateMegaPacket, RemovePendingMegaPacket, ReleaseInternalMegaPacket

Method ReleasePendingMegaPackets : Void ()

This releases all pending (Local) MegaPacket objects.

Calling this is considered unsafe; use at your own risk. This will result in timeouts on receiving ends.

This destructor is protected.

Method ReleaseReliablePacket : Bool ( ID:PacketID )

This deallocates the ReliablePacket with the identifier specified (ID).

For details, view the DeallocateReliablePacket method's documentation.

If unsure, don't mess with this.

This method is protected.

Method ReleaseWaitingMegaPacket : Void ( C:Client, MP:MegaPacket )

This removes MP (A remote MegaPacket) from an internal container in C, then releases it.

This automatically calls RemoveWaitingMegaPacket and ReleaseInternalMegaPacket

This method is protected.

See also: AllocateMegaPacket, RemoveWaitingMegaPacket, ReleaseInternalMegaPacket

Method RemovePendingMegaPacket : Void ( MP:MegaPacket )

This is used to remove one of our pending MegaPacket objects.

For more information, view the AddPendingMegaPacket command.

This method is protected.

See also: AddPendingMegaPacket, GetPendingMegaPacket

Method RemovePendingMegaPacket : Void ( ID:PacketID )

This is used to remove one of our pending MegaPacket objects using its ID.

For more information, view the main overload, and the AddPendingMegaPacket command.

This method is protected.

See also: AddPendingMegaPacket, GetPendingMegaPacket

Method RemoveSystemPacket : Void ( P:Packet )

This is called internally to remove a Packet handle previously given to AddSystemPacket.

For details on "system packets", please view that method's documentation.

In the case of automatically allocated "system packets", this should be used instead of DeallocateSystemPacket, if you intend to keep the object yourself. (Like a normal Packet from AllocatePacket)

Or, in the case of custom Packet objects, this provides removal without pooling.

If unsure, don't mess with this.

This method is protected.

See also: AddSystemPacket, AllocateSystemPacket, DeallocateSystemPacket

Method RemoveWaitingPacket : Void ( Data:DataBuffer )

This find a "system packet" associated with Data, and calls DeallocateSystemPacket on it.

For details on "system packets", view the AddSystemPacket command's documentation.

If unsure, don't mess with this.

This method is protected.

Method RetrieveWaitingPacketHandle : Packet ( Data:DataBuffer )

This looks through registered "system packets", checking for the Packet object with the same underlying buffer as Data.

For details on "system packets", view the AddSystemPacket command's documentation.

This method is protected.

Method Send : Void ( RP:ReliablePacket, Async:Bool=false )

This sends a pre-serialized ReliablePacket object.

NOTE: This overload only applies to unreliable transport. (UDP, for example) Transport protocols like TCP do not support this kind of operation, and usage will result in undefined behavior.

All ReliablePackets should contain the entire raw message, including the reliable packet meta-data. This will send RP as a raw packet using its Destination property.

Method Send : Void ( P:Packet, Type:MessageType, Reliable:Bool=false, Async:Bool=true, ExtendedPacket:Bool=false )

This builds and sends a packet of Type using P as the data-segment, and sends to every connected Client. For hosts, this sends to clients, for clients, this sends to the host.

Please enable Reliable if you intend for the message to always be received, even when using reliable transport.

  • The P argument represents the data you would like to send. (Packet formatting handled behind the scenes)
  • The Type argument specifies a user-level type defined by your application. (Must be MSG_TYPE_CUSTOM or above; non-zero currently)
  • The Reliable argument is used to ensure this packet makes it to its destinations. Packet ordering is not guaranteed; transport dependent.
  • The Async argument is used to toggle asynchronous output; queued, could be slower.
  • The ExtendedPacket argument is used internally to send packet chunks for MegaPacket objects. Unless you're extending the framework, DO NOT change this argument.

Method Send : Void ( P:Packet, C:Client, Type:MessageType, Reliable:Bool=false, Async:Bool=true, ExtendedPacket:Bool=false )

This builds and sends a packet of Type using P as the data-segment, and sends to C. For hosts, this sends to C, for clients, this will only send to C if it is Remote.

  • The P argument represents the data you would like to send. (Packet formatting handled behind the scenes)
  • The Type argument specifies a user-level type defined by your application. (Must be MSG_TYPE_CUSTOM or above)
  • The Reliable argument is used to ensure this packet makes it to its destinations. Packet ordering is not guaranteed; transport dependent.
  • The Async argument is used to toggle asynchronous output; queued, could be slower.
  • The ExtendedPacket argument is used internally to send packet chunks for MegaPacket objects. Unless you're extending the framework, DO NOT change this argument.

Method Send : Void ( MP:MegaPacket, C:Client, Type:MessageType )

This overload provides an easy to use interface for sending MegaPacket objects. MegaPacket messages are always reliable. When this message is received on the other end, it will be done as a MegaPacket, and passed to your application as a Stream.

  • The MP argument represents the auto-formatted user-level data you'd like to send.
  • The C argument acts as the destination we'll be sending to. (Follows the usual Client output rules)
  • The Type argument specifies a user-level type defined by your application. (Must be MSG_TYPE_CUSTOM or above)

Method SendConnectMessage : Void ( Async:Bool=false )

This sends a connection message (INTERNAL_MSG_CONNECT) to the default destination (Host). Basically, this is what a client uses to connect to a host network.

This method is protected.

See also: Send, AutoSendRaw

Method SendDisconnect : Void ( C:Client )

ATTENTION: This routine does not perfectly disconnect Clients objects on its own.

This command should only be called by users for debugging purposes, or in the case of lax disconnection environments.

This is used internally by DisconnectClient, which is the proper way to disconnect a Client from this network.

Method SendDisconnectToAll : Void ()

This will send reliable disconnection messages to all connected clients. The rules applied to SendDisconnect apply here, the difference being that this should only be called by hosts.

See also: ForceDisconnect, DisconnectAll, Disconnect, SendDisconnect, SendForceDisconnect, SendDisconnectionNotice

Method SendDisconnectionNotice : Void ( Reliable:Bool=false, Async:Bool=false )

This overload uses automated destination resolution.

To put it simply, this will send to the host for clients, and send to every client for a server.

By default, like SendForceDisconnect, this is not a reliable message, and may need further management after calling.

If Reliable is enabled, this will send a INTERNAL_MSG_REQUEST_DISCONNECTION message. If it's disabled, INTERNAL_MSG_DISCONNECT will be sent.

See also: ForceDisconnect, DisconnectAll, Disconnect, SendDisconnect, SendForceDisconnect, SendDisconnectToAll

Method SendForceDisconnect : Void ( C:Client, Reliable:Bool=false, Async:Bool=false )

ATTENTION: Use ForceDisconnect instead. The only exception is if you intend to manage C yourself. (Use at your own risk)

The Client specified (C) will be in its original state after calling this. However, this will send an unreliable disconnection-notice to C. Because of this, it is a bad idea to call this and not claim C as closing (Manually). This is completely unmanaged, so it's up to the caller to handle C properly.

Technically, a "force disconnect" is unmanaged, so the best course of action would be to ignore the client everywhere.

There's two ways of doing this, the safe way, and the unsafe way:

  • The safe way is considered best practice. After calling this command, manually call ReleaseClient. This will result in a proper disconnection from the host's perspective.
  • The unsafe way would be to set the C argument's Closing flag. Doing this is a bad idea for forced disconnections, as internal messages will still be accepted.
And, if ClientMessagesAfterDisconnect is on, normal messages will work, too.

See also: ForceDisconnect, DisconnectAll, Disconnect

Method SendForceDisconnect : Void ( Reliable:Bool=false, Async:Bool=false )

This acts like the other overload, only it sends to the default destination. This is used internally, and should be avoided by normal users. (Use at your own risk)

See also: ForceDisconnect, DisconnectAll, Disconnect

Method SendForceDisconnect : Void ( Address:NetworkAddress )

ATTENTION: This overload is UDP-only; use at your own risk.

This will send a disconnection message to the address specified. (INTERNAL_MSG_DISCONNECT) Since this doesn't rely on Client objects, such behavior is unrelated. If you're using a Client object's address for this, you're "doing it wrong". You should use Disconnect, or ForceDisconnect instead.

Though less ideal, but still a better option than this, is the other overload(s) for this command.

Calling this on a Client object's address will result in partially undefined behavior. The likely outcome is a connection time-out.

This method is protected.

See also: Disconnect, ForceDisconnect, Close, CloseAsync

Method SendMegaPacketChunk : Void ( P:Packet, MP:MegaPacket, Async:Bool=false )

This acts as a semi-automated send-routine for MessagePacket "chunks". (Sending end only)

This will send P using MP's meta-data.

This method is protected.

Method SendMegaPacketChunkLoadRequest : Void ( MP:MegaPacket, IsTheirPacket:Bool, Async:Bool=true )

This is used to request that the remote end handles the chunks described by MP. (INTERNAL_MSG_MEGA_PACKET_ACTION; MEGA_PACKET_ACTION_REQUEST_CHUNK_LOAD)

The IsTheirPacket argument specifies if this was started as their MegaPacket or ours.

This method is protected.

Method SendMegaPacketChunkRequest : Void ( MP:MegaPacket, Link:Int, Async:Bool=true )

This is used to request a "chunk" from a MegaPacket established on the other end (MP's Destination). The Link argument specifies the "link" (Chunk) of MP to send. (INTERNAL_MSG_MEGA_PACKET_ACTION; MEGA_PACKET_ACTION_REQUEST_CHUNK)

This method is protected.

Method SendMegaPacketChunkRequest : Bool ( MP:MegaPacket, Async:Bool=true )

This acts as an automated version of the main overload (Receiving end only); uses the internal link-position to keep track of chunks. (Modifies MP by changing the current link) - (INTERNAL_MSG_MEGA_PACKET_ACTION; MEGA_PACKET_ACTION_REQUEST_CHUNK)

If MegaPacket.OnFinalLink reports True before sending, this will still send the final chunk request, but when finishing, it will return False.

This indicates that we have finished sending requests.

This method is protected.

Method SendMegaPacketChunkResize : Void ( MP:MegaPacket, Async:Bool=true )

This tells the other end to perform a resize action (Number of chunks) on MP; limited by MaxChunksPerMegaPacket. (INTERNAL_MSG_MEGA_PACKET_ACTION; MEGA_PACKET_ACTION_CHUNK_RESIZE)

This method is protected.

Method SendMegaPacketClose : Void ( MP:MegaPacket, IsTheirPacket:Bool=true, Reliable:Bool=true, Async:Bool=true )

This is used to close a MegaPacket (MP). (INTERNAL_MSG_MEGA_PACKET_RESPONSE; MEGA_PACKET_RESPONSE_CLOSE)

The IsTheirPacket argument specifies if we're closing one of their MegaPackets, or one of ours.

This method is protected.

Method SendMegaPacketConfirmation : Void ( MP:MegaPacket, Reliable:Bool=true, Async:Bool=true )

This is used to confirm a MegaPacket (MP). (INTERNAL_MSG_MEGA_PACKET_RESPONSE; MEGA_PACKET_RESPONSE_ACCEPT)

(Not to be confused with requesting)

This method is protected.

Method SendMegaPacketRejection : Void ( ID:PacketID, Reason:PacketExtResponse, IsTheirPacket:Bool, C:Client, Reliable:Bool=true, Async:Bool=true )

This is used to reject a MegaPacket object. (INTERNAL_MSG_MEGA_PACKET_RESPONSE) Basically, this handles network-output for AbortMegaPacket.

The IsTheirPacket argument specifies if this is an anouncement of one of our MegaPackets being closed prematurely, or one of theirs.

This method is protected.

Method SendMegaPacketRejection : Void ( MP:MegaPacket, Reason:PacketExtResponse, IsTheirPacket:Bool, Reliable:Bool=true, Async:Bool=true )

This works like the main overload, only this one takes a MegaPacket, and uses its meta-data (ID). (INTERNAL_MSG_MEGA_PACKET_RESPONSE)

This method is protected.

Method SendMegaPacketRequest : Void ( MP:MegaPacket, C:Client, Reliable:Bool=true, Async:Bool=true )

This is used to initiate sending a MegaPacket (MP) to C. (INTERNAL_MSG_REQUEST_MEGA_PACKET)

(Not to be confused with confirmation)

This method is protected.

Method SendPacketConfirmation : Void ( C:Client, ID:PacketID, Async:Bool=false )

This is used to tell C that we received their reliable packet with ID as its identifier. (INTERNAL_MSG_PACKET_CONFIRM)

This method is protected.

Method SendPing : Void ( C:Client, Async:Bool=false )

This sends an INTERNAL_MSG_PING "title message" to C.

This method is protected.

See also: SendPong

Method SendPing : Void ( Async:Bool=false )

This sends an INTERNAL_MSG_PING "title message" to the default destination.

This overload is primarily for hosts; use at your own risk.

This method is protected.

See also: SendPong

Method SendPong : Void ( C:Client, Async:Bool=false )

This sends an INTERNAL_MSG_PONG "title message" to C.

This method is protected.

See also: SendPing

Method SendPong : Void ( Async:Bool=false )

This sends an INTERNAL_MSG_PONG "title message" to the default destination.

This overload is primarily for clients; use at your own risk.

This method is protected.

See also: SendPing

Method SendStandaloneMegaPacketAction : Void ( MP:MegaPacket, Action:PacketExtAction, IsTheirPacket:Bool, Async:Bool=true )

This should only be used for standalone MegaPacket actions. (INTERNAL_MSG_MEGA_PACKET_ACTION) Actions may only be performed on previously established MegaPackets.

This method is protected.

Method SendTitleMessage : Void ( InternalType:MessageType, Reliable:Bool=true, Async:Bool=true )

This sends an internal message in name only. This overload uses the default destination for Send. A "title message" is an internal message that only consists of the message's title/internal-type. This is useful for basic messages like connection pings, connections/disconnections, etc.

This method is protected.

See also: Send, AutoSendRaw

Method SendTitleMessage : Void ( InternalType:MessageType, C:Client, Reliable:Bool=true, Async:Bool=true )

This sends a "title message" to C. Normal sending behavior applies here.

For details on "title messages", view the main overload's documentation.

This method is protected.

See also: Send, AutoSendRaw

Method SendTitleMessage : Void ( InternalType:MessageType, Address:NetworkAddress, Async:Bool=true )

This sends a "title message" to Address. This only really works for UDP hosts (Or similar).

For details on "title messages", view the main overload's documentation.

This method is protected.

See also: Send, AutoSendRaw

Method SendWarningMessage : Void ( PostType:MessageType, C:Client, Reliable:Bool=true, Async:Bool=true )

This sends a warning message (INTERNAL_MSG_WARNING) to C. Basically, this is a way for a remote node to tell you that a message was used improperly. For now, these messages are internal, and don't do much. They're mainly a debugging tool.

This method is protected.

See also: Send, AutoSendRaw

Method SendWithMegaPacket : Void ( Data:Packet, Info:MegaPacket, Reliable:Bool=true, Async:Bool=false, Extended:Bool=false )

This sends Data using the information provided (Info). This is used to automate destination management for MegaPacket objects. This should only be called with MegaPackets that have appropriate meta-data.

This method is protected.

See also: Send

@ Method SendWithMegaPacket:Void(Data:Packet, Info:MegaPacket, Type:MessageType, Reliable:Bool=True, Async:Bool=False, Extended:Bool=False)

Like the main overload, this sends Data using its destination. However, if no destination is supplied, this will send without one.

This method is protected.

See also: Send

Method SetCallback : Void ( Callback:NetworkListener )

This sets every callback handle to Callback.

See also: SetCoreCallback, SetMetaCallback, SetClientCallback, SetMegaPacketCallback

Method SetClientCallback : Void ( Callback:ClientNetworkListener )

This sets the client callback handle to Callback.

Method SetCoreCallback : Void ( Callback:CoreNetworkListener )

This sets the core callback handle to Callback.

Method SetMegaPacketCallback : Void ( Callback:MegaPacketNetworkListener )

This sets the mega-packet callback handle to Callback.

Method SetMetaCallback : Void ( Callback:MetaNetworkListener )

This sets the meta callback handle to Callback.

Method TimedOut : Bool ( C:Client )

This checks if C has timed out. This framework reserves the right to ignore meta-data for this action when needed.

Method Update : Void ()

Call this every time when you intend to update details of the network. For example, this routine calls UpdateClients, which handles timeouts.

If the network has yet to be opened, this will do nothing. (Always safe)

See also: UpdateClients

Method UpdateClients : Void ()

This routine handles all connected clients and their handles. This includes things like reliable-packet routines / calling the Client class's Update method, checking for timeouts, etc.

See also: Update

Method WriteMessage : Void ( Output:Packet, Type:MessageType, Input:Packet=null, ExtendedPacket:Bool=false, DefaultSize:Int=0 )

This method's prototype may change at a later date.

This writes a message into Output using Input with Type. When writing raw packets, please call BuildOutputMessage or BuildReliableMessage, instead of calling this directly. This message does not handle the "reliable packet boolean", before this part of the message-segment. That reliable message "header" is expected on some transport protocols, such as UDP. Because of this, please call the proper "build" commands.

If your intent is to write or send a normal user-level packet, use AllocatePacket, Send, and finally ReleasePacket

  • The Output argument acts as the raw output stream for this operation.
  • The Type argument represents the user-level type of this message.
  • The Input argument is optional, and is used for the data-segment of the packet. NOTE: When using MSG_TYPE_INTERNAL, this will directly serialize to the packet after the header.
  • The ExtendedPacket argument should always be False, unless you're writing a chunk of a user-defined message for a MegaPacket. (If unsure, leave blank, use default implicit argument)
  • Changing the DefaultSize argument from zero is "unsafe", unless you intend to related data to Output after the calling this.

This method is protected.

See also: BuildOutputMessage, BuildReliableMessage, AllocatePacket, Send, ReleasePacket


Function Documentation

Function AddressesEqual : Bool ( X:NetworkAddress, Y:NetworkAddress )

This compares X and Y, and returns True if they are equal. (Deep compare)

Function ProtocolToString : String ( Protocol:ProtocolType )

This returns a string representation of Protocol.

Protocol TypeOutput
SOCKET_TYPE_UDP"UDP"
SOCKET_TYPE_TCP"TCP"