Search Results for

    Show / Hide Table of Contents

    Class NetworkPeer

    Low-level network peer class. Provides server-client communication functions, message processing and sending.

    Inheritance
    System.Object
    Object
    NetworkPeer
    Inherited Members
    Object.__unmanagedPtr
    Object.__internalId
    Object.Finalize()
    Object.As<T>()
    Object.NewValue(Type)
    Object.New(String)
    Object.Find<T>(Guid, Boolean)
    Object.Find(Guid, Type, Boolean)
    Object.TryFind<T>(Guid)
    Object.TryFind(Guid, Type)
    Object.Destroy(Object, Single)
    Object.DestroyNow(Object)
    Object.Destroy<T>(T, Single)
    Object.Equals(Object)
    Object.GetUnmanagedPtr(Object)
    Object.GetUnmanagedInterface(Object, Type)
    Object.FromUnmanagedPtr(IntPtr)
    Object.MapObjectID(Guid)
    Object.RemapObjectID(Guid)
    Object.GetHashCode()
    Object.ID
    Object.TypeName
    Namespace: FlaxEngine.Networking
    Assembly: FlaxEngine.CSharp.dll
    Syntax
    [Unmanaged]
    public sealed class NetworkPeer : Object

    Constructors

    NetworkPeer()

    Initializes a new instance of the NetworkPeer.

    Declaration
    public NetworkPeer()

    Properties

    NetworkDriver

    Low-level network transport driver used by this peer.

    Declaration
    [Unmanaged]
    public INetworkDriver NetworkDriver { get; set; }
    Property Value
    INetworkDriver

    Peers

    List with all active peers.

    Declaration
    [Unmanaged]
    public static NetworkPeer[] Peers { get; }
    Property Value
    NetworkPeer[]

    Methods

    AbortSendMessage(NetworkMessage)

    Aborts given message send. This effectively deinitializes the message and returns it to the pool.

    Declaration
    [Unmanaged]
    public void AbortSendMessage(NetworkMessage message)
    Parameters
    NetworkMessage message

    The message.

    BeginSendMessage()

    Acquires new message from the pool and setups it for sending.

    Declaration
    [Unmanaged]
    public NetworkMessage BeginSendMessage()
    Returns
    NetworkMessage

    The acquired message.

    Connect()

    Starts connection handshake with the end point specified in the NetworkConfig structure. Once this is called, this peer becomes a client.

    Declaration
    [Unmanaged]
    public bool Connect()
    Returns
    System.Boolean

    True when succeeded.

    CreateMessage()

    Acquires new message from the pool. Cannot acquire more messages than the limit specified in the NetworkConfig structure.

    Declaration
    [Unmanaged]
    public NetworkMessage CreateMessage()
    Returns
    NetworkMessage

    The acquired message.

    Remarks

    Make sure to recycle the message to this peer once it is no longer needed!

    CreatePeer(NetworkConfig)

    Creates new peer using given configuration.

    Declaration
    [Unmanaged]
    public static NetworkPeer CreatePeer(NetworkConfig config)
    Parameters
    NetworkConfig config

    The configuration to create and setup new peer.

    Returns
    NetworkPeer

    The peer.

    Remarks

    Peer should be destroyed using ShutdownPeer(NetworkPeer) once it is no longer in use. Returns null if failed to create a peer (eg. config is invalid).

    Disconnect()

    Disconnects from the server.

    Declaration
    [Unmanaged]
    public void Disconnect()
    Remarks

    Can be used only by the client!

    Disconnect(NetworkConnection)

    Disconnects given connection from the server.

    Declaration
    [Unmanaged]
    public void Disconnect(NetworkConnection connection)
    Parameters
    NetworkConnection connection

    Remarks

    Can be used only by the server!

    EndSendMessage(NetworkChannelType, NetworkMessage)

    Sends given message over specified channel to the server.

    Declaration
    [Unmanaged]
    public bool EndSendMessage(NetworkChannelType channelType, NetworkMessage message)
    Parameters
    NetworkChannelType channelType

    The channel to send the message over.

    NetworkMessage message

    The message.

    Returns
    System.Boolean

    Remarks

    Can be used only by the client!

    EndSendMessage(NetworkChannelType, NetworkMessage, NetworkConnection)

    Sends given message over specified channel to the given client connection (target).

    Declaration
    [Unmanaged]
    public bool EndSendMessage(NetworkChannelType channelType, NetworkMessage message, NetworkConnection target)
    Parameters
    NetworkChannelType channelType

    The channel to send the message over.

    NetworkMessage message

    The message.

    NetworkConnection target

    The client connection to send the message to.

    Returns
    System.Boolean

    Remarks

    Can be used only by the server!

    EndSendMessage(NetworkChannelType, NetworkMessage, NetworkConnection[])

    Sends given message over specified channel to the given client connection (target).

    Declaration
    [Unmanaged]
    public bool EndSendMessage(NetworkChannelType channelType, NetworkMessage message, NetworkConnection[] targets)
    Parameters
    NetworkChannelType channelType

    The channel to send the message over.

    NetworkMessage message

    The message.

    NetworkConnection[] targets

    The connections list to send the message to.

    Returns
    System.Boolean

    Remarks

    Can be used only by the server!

    Listen()

    Starts listening for incoming connections. Once this is called, this peer becomes a server.

    Declaration
    [Unmanaged]
    public bool Listen()
    Returns
    System.Boolean

    True when succeeded.

    PopEvent(out NetworkEvent)

    Tries to pop an network event from the queue.

    Declaration
    [Unmanaged]
    public bool PopEvent(out NetworkEvent eventRef)
    Parameters
    NetworkEvent eventRef

    The reference to event structure.

    Returns
    System.Boolean

    True when succeeded and the event can be processed.

    Remarks

    If this returns message event, make sure to recycle the message using RecycleMessage(NetworkMessage) function after processing it!

    RecycleMessage(NetworkMessage)

    Returns given message to the pool.

    Declaration
    [Unmanaged]
    public void RecycleMessage(NetworkMessage message)
    Parameters
    NetworkMessage message

    Remarks

    Make sure that this message belongs to the peer and has not been recycled already (debug build checks for this)!

    ShutdownPeer(NetworkPeer)

    Shutdowns and destroys given peer.

    Declaration
    [Unmanaged]
    public static void ShutdownPeer(NetworkPeer peer)
    Parameters
    NetworkPeer peer

    The peer to destroy.

    Extension Methods

    Extensions.ReflectiveCompare<T>(T, T)
    Extensions.DeepClone<T>(T)
    Extensions.RawClone<T>(T)
    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat