mzehr.net: | Types | Modinfo | Source |
TNetClient | Class used to establish a connection with a server. |
TNetClientEvent | An event raised by the client. |
TNetPacket | A data packet/message. Data can be written into or read from the packet. |
TNetPeer | Represents a peer/client/player on the server. |
TNetServer | Class used to run a server. |
TNetServerEvent | An event raised by the server. |
Type TNetClient | |
Description | Class used to establish a connection with a server. |
Methods Summary | |
---|---|
Connect | Establishes a connection with a server. |
Disconnect | Closes the connection to the server. |
Flush | Sends all buffered messages as soon as possible or immediately. |
Send | Sends a packet / a message to the server. |
Update | Updates the client (receives and sends messages). |
Functions Summary | |
---|---|
Create | Creates a new and unconnected client. |
Method Connect:Int(host:String, port:Int, connectTimeout:Int = 5000, channelCount:Int = 2) | |
Returns | True if the connection has been established, False if not. |
Description | Establishes a connection with a server. |
Information | host:String IP address or hostname on which to listen for incoming connections. port:Int Port on which to listen for incoming connections. connectTimeout:Int (Optional) Maximum time in ms to wait for the connection. channelCount:Int (Optional) Number of communication channels. Will be limited to 1-255. (Default: 2) |
Method Disconnect(disconnectTime:Int = 2000) | |
Description | Closes the connection to the server. |
Information | disconnectTime:Int (Optional) Maximum time in ms to wait for remaining messages to be sent before the connection will be closed. |
Method Flush() | |
Description | Sends all buffered messages as soon as possible or immediately. |
Information | It's better to use Update, because Update does almost the same and also receives incoming messages. |
Method Send(packet:TNetPacket, reliable:Int = False, channel:Int = 0, compressed:Int = False) | |
Description | Sends a packet / a message to the server. |
Information | packet:TNetPacket The packet that will be sent reliable:Int (Optional) Whether the packet should be sent reliable or not (Default: False, this is suitable for unimportant anf fast data like player positions) channel:Int (Optional) The channel used for transmitting the packet (Default: 0, reliable/important messages should be sent on a different channel than unimportant messages, for example channel 1) compressed:Int (Optional) Whether the data will be compressed or not (Default: False, should only be used with large data, i.e. when sending 100x100 tiles etc.) |
Method Update:TNetClientEvent(waitTime:Int = 0) | |
Returns | An object of type TNetClientEvent that represents the last event or Null if there was no event. |
Description | Updates the client (receives and sends messages). |
Information | waitTime:Int (Optional) Time in ms to wait for incoming messages. (Default = 0, this means the function will return immediatley if there are no messages to receive). |
Function Create:TNetClient() | |
Description | Creates a new and unconnected client. |
Type TNetClientEvent | |
Description | An event raised by the client. |
Constants Summary | |
---|---|
CONNECT , DATA , DISCONNECT |
Fields Summary | |
---|---|
Channel , Event , Packet |
Const CONNECT:Int | |
Description | Server: A new client has established a connection with the server. | Client: The connection with the server has been established. |
Const DATA:Int | |
Description | Data received (client: from the server | server: from a specific client). |
Const DISCONNECT:Int | |
Description | The connection was closed (client: connection with the server | server: connection with a specific client). |
Field Channel:Int | |
Description | The channel on which the packet was received. |
Field Event:Int | |
Description | Event that was raised (equals to TNetClientEvent.CONNECT or DATA). |
Field Packet:TNetPacket | |
Description | The packet that was received (only available in a DATA event). |
Type TNetPacket | |
Description | A data packet/message. Data can be written into or read from the packet. |
Methods Summary | |
---|---|
Destroy | Releases the memory used by the packet. |
EnetPacket | Converts the packet to an ENet packet struct. |
Read | Reads multiple Bytes from the packet and writes them to the specified memory location. |
ReadByte | Reads a byte from the packet. |
ReadBytes | Reads multiple Bytes from the packet and writes them to the specified memory location. |
ReadDouble | Reads a double from the packet. |
ReadFloat | Reads a float from the packet. |
ReadInt | Reads an int from the packet. |
ReadLine | Reads a line of text from the packet. |
ReadLong | Reads a long from the packet. |
ReadObject | Reads an object from the packet (untested). |
ReadShort | Reads a short from the packet. |
ReadString | Reads a string from the packet. |
Write | Writes multiple bytes into the packet. |
WriteByte | Writes a byte into the packet. |
WriteBytes | Writes multiple bytes into the packet. |
WriteDouble | Writes a double into the packet. |
WriteFloat | Writes a float into the packet. |
WriteInt | Writes an int into the packet. |
WriteLine | Writes a line of text into the packet. |
WriteLong | Writes a long into the packet. |
WriteObject | Writes an object to the packet (untested). |
WriteShort | Writes a short into the packet. |
WriteString | Writes a string into the packet. |
Functions Summary | |
---|---|
Create | Creates a new packet (for sending). |
FromEnet | Reads a packet from an ENet packet struct. |
Method Destroy() | |
Description | Releases the memory used by the packet. |
Information | Will be called automatically on deconstruction of the object (garbage collector), but can also be called manually. |
Method EnetPacket:Byte Ptr(enet_flags:Int = 0, compressed:Int = False) | |
Description | Converts the packet to an ENet packet struct. |
Information | This method is used internally and should not be called manually. |
Method Read:Int(buf:Byte Ptr, count:Int) | |
Returns | Number of successfully read bytes. |
Description | Reads multiple Bytes from the packet and writes them to the specified memory location. |
Information | buf:Byte Ptr Memory location where the bytes will be written to. count:Int Number of bytes that should be read. |
Method ReadByte:Byte() | |
Description | Reads a byte from the packet. |
Method ReadBytes:Int(buf:Byte Ptr, count:Int) | |
Returns | Number of successfully read bytes. |
Description | Reads multiple Bytes from the packet and writes them to the specified memory location. |
Information | buf:Byte Ptr Memory location where the bytes will be written to. count:Int Number of bytes that should be read. |
Method ReadDouble:Double() | |
Description | Reads a double from the packet. |
Method ReadFloat:Float() | |
Description | Reads a float from the packet. |
Method ReadInt:Int() | |
Description | Reads an int from the packet. |
Method ReadLine:String() | |
Description | Reads a line of text from the packet. |
Method ReadLong:Long() | |
Description | Reads a long from the packet. |
Method ReadObject:Object() | |
Description | Reads an object from the packet (untested). |
Method ReadShort:Short() | |
Description | Reads a short from the packet. |
Method ReadString:String() | |
Description | Reads a string from the packet. |
Information | Reads an int that specifies the length of the string and then the string itself. |
Method Write(buf:Byte Ptr, count:Int) | |
Description | Writes multiple bytes into the packet. |
Information | buf:Byte Ptr Memory location from where the data is read and then written to the packet. count:Int Number of bytes that should be read/written. |
Method WriteByte(value:Byte) | |
Description | Writes a byte into the packet. |
Method WriteBytes(buf:Byte Ptr, count:Int) | |
Description | Writes multiple bytes into the packet. |
Information | buf:Byte Ptr Memory location from where the data is read and then written to the packet. count:Int Number of bytes that should be read/written. |
Method WriteDouble(value:Double) | |
Description | Writes a double into the packet. |
Method WriteFloat(value:Float) | |
Description | Writes a float into the packet. |
Method WriteInt(value:Int) | |
Description | Writes an int into the packet. |
Method WriteLine(value:String) | |
Description | Writes a line of text into the packet. |
Method WriteLong(value:Long) | |
Description | Writes a long into the packet. |
Method WriteObject(value:Object) | |
Description | Writes an object to the packet (untested). |
Method WriteShort(value:Short) | |
Description | Writes a short into the packet. |
Method WriteString(value:String) | |
Description | Writes a string into the packet. |
Information | Writes an int containing the length of the string followed by the string itself. |
Function Create:TNetPacket() | |
Description | Creates a new packet (for sending). |
Function FromEnet:TNetPacket(p:Byte Ptr) | |
Description | Reads a packet from an ENet packet struct. |
Information | This function is used internally and should not be called manually. |
Type TNetPeer | |
Description | Represents a peer/client/player on the server. |
Methods Summary | |
---|---|
GetData | Gets the data assigned to this peer (see SetData). |
GetPeer | Returns the ENet peer struct. |
SetData | Assigns a custom data object to this peer. |
Functions Summary | |
---|---|
Create | Creates a new peer from an ENet peer struct. |
Method GetData:Object() | |
Description | Gets the data assigned to this peer (see SetData). |
Method GetPeer:Byte Ptr() | |
Description | Returns the ENet peer struct. |
Information | This methos is used internally by the server and should not be called manually. |
Method SetData(value:Object) | |
Description | Assigns a custom data object to this peer. |
Information | This can be used to assign a player object or other data to the peer. On the server, you can retrieve a list of connected peers with TNetServer.GetClients() and those peers (TNetPeer) contain the assigned data object which can be fetched by calling TNetPeer.GetData(). |
Function Create:TNetPeer(peer:Byte Ptr) | |
Description | Creates a new peer from an ENet peer struct. |
Information | This method is used internally by the server and should not be called manually. |
Type TNetServer | |
Description | Class used to run a server. |
Methods Summary | |
---|---|
Broadcast | Sends a packet to all connected peers / players. |
DisconnectClient | Sends a disconnect message to the peer / player and closes the connection after the message has been acknowledged. |
DropClient | Closes the connection to a peer immediately. The peer won't be notified and will only notice the disconnection after the ping timeout. |
Flush | Sends all buffered messages as soon as possible or immediately. |
GetClients | Gets a list containing all the connected peers / players. |
Send | Sends a packet to the specified peer / player. |
Shutdown | Shuts down the server. |
Update | Updates the server (receives and sends messages). |
Functions Summary | |
---|---|
Create | Creates a new server that listens for incoming connections on the specified ip address and port. |
Method Broadcast(packet:TNetPacket, reliable:Int = False, channel:Int = 0, compressed:Int = False) | |
Description | Sends a packet to all connected peers / players. |
Information | packet:TNetPacket The packet that will be sent. reliable:Int (Optional) Whether the packet should be sent reliable or not (Default: False, this is suitable for unimportant anf fast data like player positions) channel:Int (Optional) The channel used for transmitting the packet (Default: 0, reliable/important messages should be sent on a different channel than unimportant messages, for example channel 1). compressed:Int (Optional) Whether the data will be compressed or not (Default: False, should only be used with large data, i.e. when sending 100x100 tiles etc.) |
Method DisconnectClient(peer:TNetPeer) | |
Description | Sends a disconnect message to the peer / player and closes the connection after the message has been acknowledged. |
Method DropClient(peer:TNetPeer) | |
Description | Closes the connection to a peer immediately. The peer won't be notified and will only notice the disconnection after the ping timeout. |
Method Flush() | |
Description | Sends all buffered messages as soon as possible or immediately. |
Information | It's better to use Update, because Update does almost the same and also receives incoming messages. |
Method GetClients:TList() | |
Description | Gets a list containing all the connected peers / players. |
Information | You should not modify the list in any way! Use the DisconnectClient or DropClient functions instead. |
Method Send(peer:TNetPeer, packet:TNetPacket, reliable:Int = False, channel:Int = 0, compressed:Int = False) | |
Description | Sends a packet to the specified peer / player. |
Information | peer:TNetPeer The peer / player that will receive the packet. packet:TNetPacket The packet that will be sent. reliable:Int (Optional) Whether the packet should be sent reliable or not (Default: False, this is suitable for unimportant anf fast data like player positions) channel:Int (Optional) The channel used for transmitting the packet (Default: 0, reliable/important messages should be sent on a different channel than unimportant messages, for example channel 1). compressed:Int (Optional) Whether the data will be compressed or not (Default: False, should only be used with large data, i.e. when sending 100x100 tiles etc.) |
Method Shutdown(shutdownTime:Int = 5000) | |
Description | Shuts down the server. |
Information | shutdownTime:Int (Optional) Maximum time in ms to wait for the remaining messages to be sent before shutting down. (Default: 5000) |
Method Update:TNetServerEvent(waitTime:Int = 0) | |
Returns | An object of Type TNetServerEvent tha represents the last event or null if there was no event. |
Description | Updates the server (receives and sends messages). |
Information | waitTime:Int (Optional) Time in ms to wait for incoming messages. (Default = 0, this means the function will return immediatley if there are no messages to receive). |
Function Create:TNetServer(ip:String, port:Int, maxConnections:Int, maxChannels:Int = 2) | |
Returns | An object of Type TNetServer or Null in case the server could not be started. |
Description | Creates a new server that listens for incoming connections on the specified ip address and port. |
Information | ip:String IP address on which to listen for incoming connections (use Null, "127.0.0.1" or "localhost" to listen on all local addresses). port:Int Port number (should be greater than 1000 and as high as possible, i.e. 50000 or another number that is not used by other protocols or services). maxConnections:Int Maximum number of allowed connections / players. maxChannels:Int (Optional) Maximum number of communication channels. Will be limited to 1-255. (Default: 2) |
Type TNetServerEvent Extends TNetClientEvent | |
Description | An event raised by the server. |
Fields Summary | |
---|---|
Peer |
Field Peer:TNetPeer | |
Description | The client that received data/connected/disconnected. |
Author | Michael Zehr (Jolinah) |
---|---|
License | MIT X11 License (License.txt) |
Credit | Lee Salzman (http://enet.bespin.org) |
History | 1.0 First release |
History | 1.1 Instead of importing pub.enet, the newest source code of ENet has been compiled into the module (version 1.3.13 as of now). However, the protocol of ENet version 1.3 and above is not compatible with ENet versions 1.2 and below. You will need to redistribute the client to all existing players after updating the server or they won't be able to play on the new server. |