docs.unity3d.com
    Show / Hide Table of Contents

    Struct NetworkPacketReceiver

    The NetworkPacketReceiver is an interface for handling received packets, needed by the INetworkInterface It either can be used in two main scenarios:

    1. Your API requires a pointer to memory that you own. Then you should use AllocateMemory(ref Int32), write to the memory and then AppendPacket(IntPtr, ref NetworkInterfaceEndPoint, Int32, NetworkPacketReceiver.AppendPacketMode) with NoCopyNeeded. You don't need to deallocate the memory
    2. Your API gives you a pointer that you don't own. In this case you should use AppendPacket(IntPtr, ref NetworkInterfaceEndPoint, Int32, NetworkPacketReceiver.AppendPacketMode) with None (default)
    Inherited Members
    ValueType.Equals(Object)
    ValueType.GetHashCode()
    ValueType.ToString()
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Namespace: Unity.Networking.Transport
    Syntax
    public struct NetworkPacketReceiver

    Properties

    LastUpdateTime

    Gets the value of the last update time.

    Declaration
    public readonly long LastUpdateTime { get; }
    Property Value
    Type Description
    Int64

    ReceiveErrorCode

    Sets the value of the receive error code

    Declaration
    public int ReceiveErrorCode { set; }
    Property Value
    Type Description
    Int32

    Methods

    AllocateMemory(ref Int32)

    Calls NetworkDriver's Unity.Networking.Transport.NetworkDriver.AllocateMemory(System.Int32@)

    Declaration
    public IntPtr AllocateMemory(ref int dataLen)
    Parameters
    Type Name Description
    Int32 dataLen

    Size of memory to allocate in bytes. Must be > 0

    Returns
    Type Description
    IntPtr

    Pointer to allocated memory or IntPtr.Zero if there is no space left (this function doesn't set ReceiveErrorCode! caller should decide if this is Out of memory or something else)

    AppendPacket(IntPtr, ref NetworkInterfaceEndPoint, Int32, NetworkPacketReceiver.AppendPacketMode)

    When data is received this function should be called to pass it inside NetworkDriver

    Declaration
    public bool AppendPacket(IntPtr data, ref NetworkInterfaceEndPoint address, int dataLen, NetworkPacketReceiver.AppendPacketMode mode = NetworkPacketReceiver.AppendPacketMode.None)
    Parameters
    Type Name Description
    IntPtr data

    Pointer to the data. If it is pointer to data that was received with AllocateMemory(ref Int32) make sure mode is NoCopyNeeded>

    NetworkInterfaceEndPoint address

    Address where data was received from

    Int32 dataLen

    Length of in bytes

    NetworkPacketReceiver.AppendPacketMode mode

    Extra flags, like NoCopyNeeded that means - no copy is needed, data is already in NetworkDriver's data stream

    Returns
    Type Description
    Boolean

    True if no errors

    IsAddressUsed(NetworkInterfaceEndPoint)

    Check if an address is currently associated with a valid connection. This is mostly useful to keep interface internal lists of connections in sync with the correct state.

    Declaration
    public bool IsAddressUsed(NetworkInterfaceEndPoint address)
    Parameters
    Type Name Description
    NetworkInterfaceEndPoint address

    Address to check.

    Returns
    Type Description
    Boolean

    Whether the address is used or not.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023