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
    Object
    ScriptingObject
    NetworkPeer
    Inherited Members
    ScriptingObject::_gcHandle
    ScriptingObject::_id
    ScriptingObject::_type
    ScriptingObject::CanCast(const ScriptingTypeHandle& from, const ScriptingTypeHandle& to)
    ScriptingObject::CanCast(const MClass* from, const MClass* to)
    ScriptingObject::Cast(ScriptingObject* obj)
    ScriptingObject::ChangeID(const Guid& newId)
    ScriptingObject::CreateManaged()
    ScriptingObject::CreateManagedInternal()
    ScriptingObject::Deleted
    Object::DeleteObject(float timeToLive = 0.0f, bool useGameTime=false)
    Object::DeleteObjectNow()
    ScriptingObject::DestroyManaged()
    Object::Flags
    ScriptingObject::FromInterface(void* interfaceObj, const ScriptingTypeHandle& interfaceType)
    ScriptingObject::FromInterface(T* interfaceObj)
    ScriptingObject::GetClass()
    ScriptingObject::GetID()
    ScriptingObject::GetManagedInstance()
    ScriptingObject::GetOrCreateManagedInstance()
    ScriptingObject::GetType()
    ScriptingObject::GetTypeHandle()
    ScriptingObject::HasManagedInstance()
    ScriptingObject::Is(const ScriptingTypeHandle& type)
    ScriptingObject::Is(const MClass* type)
    ScriptingObject::Is()
    ScriptingObject::IsRegistered()
    ScriptingObject::NewObject(const ScriptingTypeHandle& typeHandle)
    ScriptingObject::NewObject()
    ScriptingObject::OnDeleteObject()
    ScriptingObject::OnManagedInstanceDeleted()
    ScriptingObject::OnScriptingDispose()
    ScriptingObject::RegisterObject()
    ScriptingObject::ScriptingObject(const SpawnParams& params)
    ScriptingObject::SetManagedInstance(MObject* instance)
    NetworkPeer
    ScriptingObject::ToInterface(ScriptingObject* obj, const ScriptingTypeHandle& interfaceType)
    ScriptingObject::ToInterface(ScriptingObject* obj)
    ScriptingObject::ToManaged(const ScriptingObject* obj)
    ScriptingObject::ToNative(MObject* obj)
    ScriptingObject::ToString()
    ScriptingObject::UnregisterObject()
    Object::~Object()
    ScriptingObject::~ScriptingObject()
    Assembly: FlaxEngine.dll
    File: Engine/Networking/NetworkPeer.h
    Syntax
    public class NetworkPeer : public ScriptingObject

    Fields

    Config

    Declaration
    public NetworkConfig Config
    Field Value
    NetworkConfig

    HostId

    Declaration
    public int HostId = -1
    Field Value
    int

    MessageBuffer

    Declaration
    public uint8* MessageBuffer = nullptr
    Field Value
    uint8

    MessagePool

    Declaration
    public Array<uint32, HeapAllocation> MessagePool
    Field Value
    Array<uint32, HeapAllocation>

    NetworkDriver

    Low-level network transport driver used by this peer.

    Declaration
    public INetworkDriver* NetworkDriver = nullptr
    Field Value
    INetworkDriver

    Methods

    AbortSendMessage(const NetworkMessage& message)

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

    Declaration
    public void AbortSendMessage(const NetworkMessage& message)
    Parameters
    NetworkMessage message

    The message.

    BeginSendMessage()

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

    Declaration
    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
    public bool Connect()
    Returns
    bool

    True when succeeded.

    CreateMessage()

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

    NetworkConfig

    structure.

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

    Declaration
    public NetworkMessage CreateMessage()
    Returns
    NetworkMessage

    The acquired message.

    CreatePeer(const NetworkConfig& config)

    Creates new peer using given configuration.

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

    Declaration
    public static NetworkPeer* CreatePeer(const NetworkConfig& config)
    Parameters
    NetworkConfig config

    The configuration to create and setup new peer.

    Returns
    NetworkPeer

    The peer.

    Disconnect()

    Disconnects from the server.

    Can be used only by the client!

    Declaration
    public void Disconnect()

    Disconnect(const NetworkConnection& connection)

    Disconnects given connection from the server.

    Can be used only by the server!

    Declaration
    public void Disconnect(const NetworkConnection& connection)
    Parameters
    NetworkConnection connection

    EndSendMessage(NetworkChannelType channelType, const NetworkMessage& message)

    Sends given message over specified channel to the server.

    Can be used only by the client!

    Do not recycle the message after calling this. This function automatically recycles the message.

    Declaration
    public bool EndSendMessage(NetworkChannelType channelType, const NetworkMessage& message)
    Parameters
    NetworkChannelType channelType

    The channel to send the message over.

    NetworkMessage message

    The message.

    Returns
    bool

    EndSendMessage(NetworkChannelType channelType, const NetworkMessage& message, const Array<NetworkConnection, HeapAllocation>& targets)

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

    Can be used only by the server!

    Do not recycle the message after calling this. This function automatically recycles the message.

    Declaration
    public bool EndSendMessage(NetworkChannelType channelType, const NetworkMessage& message, const Array<NetworkConnection, HeapAllocation>& targets)
    Parameters
    NetworkChannelType channelType

    The channel to send the message over.

    NetworkMessage message

    The message.

    Array<NetworkConnection, HeapAllocation> targets

    The connections list to send the message to.

    Returns
    bool

    EndSendMessage(NetworkChannelType channelType, const NetworkMessage& message, const NetworkConnection& target)

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

    Can be used only by the server!

    Do not recycle the message after calling this. This function automatically recycles the message.

    Declaration
    public bool EndSendMessage(NetworkChannelType channelType, const NetworkMessage& message, const 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
    bool

    GetMessageBuffer(const uint32 messageId)

    Declaration
    public uint8* GetMessageBuffer(const uint32 messageId) const
    Parameters
    uint32 messageId

    Returns
    uint8

    IsValid()

    Declaration
    public bool IsValid() const
    Returns
    bool

    Listen()

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

    Declaration
    public bool Listen()
    Returns
    bool

    True when succeeded.

    operator!=(const NetworkPeer& other)

    Declaration
    public bool operator!=(const NetworkPeer& other) const
    Parameters
    NetworkPeer other

    Returns
    bool

    operator==(const NetworkPeer& other)

    Declaration
    public bool operator==(const NetworkPeer& other) const
    Parameters
    NetworkPeer other

    Returns
    bool

    PopEvent(NetworkEvent& eventRef)

    Tries to pop an network event from the queue.

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

    Declaration
    public bool PopEvent(NetworkEvent& eventRef)
    Parameters
    NetworkEvent eventRef

    The reference to event structure.

    Returns
    bool

    True when succeeded and the event can be processed.

    RecycleMessage(const NetworkMessage& message)

    Returns given message to the pool.

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

    Declaration
    public void RecycleMessage(const NetworkMessage& message)
    Parameters
    NetworkMessage message

    ShutdownPeer(NetworkPeer* peer)

    Shutdowns and destroys given peer.

    Declaration
    public static void ShutdownPeer(NetworkPeer* peer)
    Parameters
    NetworkPeer peer

    The peer to destroy.

    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat