• Home
  • Tutorials
  • API Documentation
  • Asset Store
Show / Hide Table of Contents
  • SuperNet.Netcode.Compress
    • CompressorDeflate
    • CompressorLZF
    • ICompressor
  • SuperNet.Netcode.Crypto
    • CryptoAES
    • CryptoECDH
    • CryptoRandom
    • CryptoRSA
    • Curve25519
    • ICryptoAuthenticator
    • ICryptoEncryptor
    • ICryptoExchanger
    • ICryptoRandom
  • SuperNet.Netcode.Transport
    • ConnectionRequest
    • DisconnectReason
    • Host
    • HostConfig
    • HostEvents
    • HostStatistics
    • HostTimespan
    • HostTimestamp
    • IHostListener
    • IMessage
    • IMessageListener
    • IPeerListener
    • MessageEvents
    • MessageReceived
    • MessageSent
    • Peer
    • PeerConfig
    • PeerEvents
    • PeerStatistics
  • SuperNet.Netcode.Util
    • Allocator
    • ArrayPool<T>
    • CRC32
    • IPComparer
    • IPResolver
    • IWritable
    • ObjectPool<T>
    • Reader
    • Serializer
    • Writer
  • SuperNet.Unity.Components
    • INetworkAuthoritative
    • INetworkRegisterable
    • INetworkRollbackable
    • NetworkAnimation
    • NetworkAnimator
    • NetworkAuthority
    • NetworkPrefab
    • NetworkRegistrar
    • NetworkSpawner
    • NetworkSyncModeMethod
    • NetworkSyncModeVector2
    • NetworkSyncModeVector3
    • NetworkTransform
  • SuperNet.Unity.Core
    • NetworkComponent
    • NetworkHost
    • NetworkIdentity
    • NetworkIdentityExtensions
    • NetworkManager
  • SuperNet.Unity.Editor
    • NetworkAuthorityEditor
    • NetworkHostEditor
    • NetworkHostEditor.BandwithUnit
    • NetworkIdentityDrawer
    • NetworkManagerEditor
    • NetworkPrefabEditor
    • NetworkSpawnerEditor

Class Host

Manages a network socket and all network communication between peers.

Inheritance
System.Object
Host
Namespace: SuperNet.Netcode.Transport
Assembly: cs.temp.dll.dll
Syntax
public class Host : IDisposable

Constructors

Host(HostConfig, IHostListener)

Create a new UDP socket and start listening for packets.

Declaration
public Host(HostConfig config, IHostListener listener)
Parameters
Type Name Description
HostConfig config

Host configuration values. If null, defaults are used.

IHostListener listener

Host listener to use. If null, event based listener is created.

Fields

Allocator

Allocator used to manage internal buffers.

Declaration
public readonly Allocator Allocator
Field Value
Type Description
Allocator

Config

Configuration values for this host.

Declaration
public readonly HostConfig Config
Field Value
Type Description
HostConfig

Frequency

Tick frequency of the host in ticks per second.

Declaration
public const long Frequency = 1000L
Field Value
Type Description
System.Int64

Statistics

Packet statistics.

Declaration
public readonly HostStatistics Statistics
Field Value
Type Description
HostStatistics

Properties

BindAddress

Address this host is listening on.

Declaration
public IPEndPoint BindAddress { get; }
Property Value
Type Description
IPEndPoint

Disposed

True if host is disposed and cannot be used anymore.

Declaration
public bool Disposed { get; }
Property Value
Type Description
System.Boolean

Listener

Listener used by this host.

Declaration
public IHostListener Listener { get; }
Property Value
Type Description
IHostListener

Now

Create a new timestamp at the current host time.

Declaration
public static HostTimestamp Now { get; }
Property Value
Type Description
HostTimestamp

SupportsIPv6

Platform dependant IPv6 support check. True if IPv6 is supported, false if not.

Declaration
public static bool SupportsIPv6 { get; }
Property Value
Type Description
System.Boolean

Ticks

Number of milliseconds that have elapsed since the host was created.

Declaration
public static long Ticks { get; }
Property Value
Type Description
System.Int64

Methods

Accept(ConnectionRequest, PeerConfig, IPeerListener)

Accept a connection request and return a connected local peer.

Declaration
public Peer Accept(ConnectionRequest request, PeerConfig config, IPeerListener listener)
Parameters
Type Name Description
ConnectionRequest request

Connection request to accept.

PeerConfig config

Peer configuration values. If null, default is used.

IPeerListener listener

Peer listener to use. If null, event based listener is created.

Returns
Type Description
Peer

Connected local peer.

Connect(IPEndPoint, PeerConfig, IPeerListener, IWritable)

Create a local peer and start connecting to an active remote host.

Declaration
public Peer Connect(IPEndPoint remote, PeerConfig config, IPeerListener listener, IWritable message = null)
Parameters
Type Name Description
IPEndPoint remote

Remote address to connect to.

PeerConfig config

Peer configuration values. If null, default is used.

IPeerListener listener

Peer listener to use. If null, PeerEvents is used.

IWritable message

Connect message to use.

Returns
Type Description
Peer

Local peer that attempts to connect.

Dispose()

Instantly dispose all resources held by this host and connected peers.

Declaration
public void Dispose()

FindPeer(IPEndPoint)

Attempt to find an existing peer based on remote address.

Declaration
public Peer FindPeer(IPEndPoint remote)
Parameters
Type Name Description
IPEndPoint remote

Remote address of the peer.

Returns
Type Description
Peer

An existing peer or null if not found.

IsLocal(IPEndPoint)

Check if address is connected locally.

Declaration
public static bool IsLocal(IPEndPoint remote)
Parameters
Type Name Description
IPEndPoint remote

Address to check.

Returns
Type Description
System.Boolean

True if address is local, false if not.

IsPortUsed(Int32)

Check if port is used by any active host.

Declaration
public static bool IsPortUsed(int port)
Parameters
Type Name Description
System.Int32 port

Port to check.

Returns
Type Description
System.Boolean

True if port is used, false if not.

Reject(ConnectionRequest, IWritable)

Reject a connection request.

Declaration
public void Reject(ConnectionRequest request, IWritable message = null)
Parameters
Type Name Description
ConnectionRequest request

Connection request to reject.

IWritable message

Rejection message.

SendAll(IMessage, Peer[])

Send a message to all connected peers.

Declaration
public void SendAll(IMessage message, params Peer[] exclude)
Parameters
Type Name Description
IMessage message

Message to send.

Peer[] exclude

Peers to exclude.

SendBroadcast(Int32, IWritable)

Send an unconnected message to all machines on the local network.

Declaration
public void SendBroadcast(int port, IWritable message)
Parameters
Type Name Description
System.Int32 port

Network port to send to.

IWritable message

Message to send.

SendBroadcastAsync(Int32, IWritable)

Send an unconnected message to all machines on the local network.

Declaration
public Task<int> SendBroadcastAsync(int port, IWritable message)
Parameters
Type Name Description
System.Int32 port

Network port to send to.

IWritable message

Message to send.

Returns
Type Description
Task<System.Int32>

Task that returns number of bytes sent.

SendUnconnected(IPEndPoint, IWritable)

Send an unconnected message to a remote host.

Declaration
public void SendUnconnected(IPEndPoint remote, IWritable message)
Parameters
Type Name Description
IPEndPoint remote

Remote address to send to.

IWritable message

Message to send.

SendUnconnectedAsync(IPEndPoint, IWritable)

Send an unconnected message to a remote host.

Declaration
public Task<int> SendUnconnectedAsync(IPEndPoint remote, IWritable message)
Parameters
Type Name Description
IPEndPoint remote

Remote address to send to.

IWritable message

Message to send.

Returns
Type Description
Task<System.Int32>

Task that returns number of bytes sent.

SetListener(IHostListener)

Replace the current listener with a new one.

Declaration
public IHostListener SetListener(IHostListener listener)
Parameters
Type Name Description
IHostListener listener

Listener to replace with.

Returns
Type Description
IHostListener

The old HostListener.

Shutdown()

Gracefully disconnect all peers and perform a shutdown.

Declaration
public void Shutdown()

ShutdownAsync()

Gracefully disconnect all peers and perform a shutdown.

Declaration
public Task ShutdownAsync()
Returns
Type Description
Task

Task that completes when shutdown is completed.

Back to top Generated by DocFX