Legacy Documentation: Version 2018.2 (Go to current version)
LanguageEnglish
  • C#

NetworkTransport

class in UnityEngine.Networking

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Transport Layer API.

Static Properties

IsStartedDeprecated.

Static Methods

AddHostCreates a host based on HostTopology.
AddHostWithSimulatorCreate a host and configure them to simulate Internet latency (works on Editor and development build only).
AddWebsocketHostCreated web socket host.
ConnectTries to establish a connection to another peer.
ConnectAsNetworkHostCreate dedicated connection to Relay server.
ConnectEndPointTry to establish connection to other peer, where the peer is specified using a C# System.EndPoint.
ConnectToNetworkPeerCreate a connection to another peer in the Relay group.
ConnectWithSimulatorConnect with simulated latency.
DisconnectSend a disconnect signal to the connected peer and close the connection. Poll NetworkTransport.Receive() to be notified that the connection is closed. This signal is only sent once (best effort delivery). If this packet is dropped for some reason, the peer closes the connection by timeout.
DisconnectNetworkHostThis will disconnect the host and disband the group. DisconnectNetworkHost can only be called by the group owner on the relay server.
FinishSendMulticastFinalizes sending of a message to a group of connections. Only one multicast message at a time is allowed per host.
GetAckBufferCountReturns size of reliable buffer.
GetBroadcastConnectionInfoAfter NetworkTransport.Receive() returns NetworkEventType.BroadcastEvent, this function will return the connection information of the broadcast sender. This information can then be used for connecting to the broadcast sender.
GetBroadcastConnectionMessageAfter NetworkTransport.Receive() returns NetworkEventType.BroadcastEvent, this function returns a complimentary message from the broadcast sender.
GetConnectionInfoReturns the connection parameters for the specified connectionId. These parameters can be sent to other users to establish a direct connection to this peer. If this peer is connected to the host via Relay, the Relay-related parameters are set.
GetCurrentRTTReturn the round trip time for the given connectionId.
GetHostPortReturns the port number assigned to the host.
GetIncomingMessageQueueSizeReturns the number of received messages waiting in the queue for processing.
GetIncomingPacketCountReturns how many packets have been received from start for connection.
GetIncomingPacketCountForAllHostsReturns how many packets have been received from start. (from NetworkTransport.Init call).
GetIncomingPacketDropCountForAllHostsHow many packets have been dropped due lack space in incoming queue (absolute value, countinf from start).
GetIncomingPacketLossCountReturns how many incoming packets have been lost due transmitting (dropped by network).
GetMaxAllowedBandwidthGets the currently-allowed network bandwidth in bytes per second. The value returned can vary because bandwidth can be throttled by flow control. If the bandwidth is throttled to zero, the connection is disconnected.ted.
GetNetworkTimestampGet a network timestamp. Can be used in your messages to investigate network delays together with Networking.GetRemoteDelayTimeMS.
GetOutgoingFullBytesCountReturns how much raw data (in bytes) have been sent from start for all hosts (from NetworkTransport.Init call).
GetOutgoingFullBytesCountForConnectionReturns how much raw data (in bytes) have been sent from start for connection (from call NetworkTransport.Connect for active connect or from connection request receiving for passive connect).
GetOutgoingFullBytesCountForHostReturns how much raw data (in bytes) have been sent from start for the host (from call NetworkTransport.AddHost).
GetOutgoingMessageCountReturns how many messages have been sent from start (from NetworkTransport.Init call).
GetOutgoingMessageCountForConnectionReturns how many packets have been sent from start for connection (from call NetworkTransport.Connect for active connect or from connection request receiving for passive connect).
GetOutgoingMessageCountForHostReturns how many messages have been sent from start for host (from call NetworkTransport.AddHost).
GetOutgoingMessageQueueSizeReturns the number of messages waiting in the outgoing message queue to be sent.
GetOutgoingPacketCountReturns how many packets have been sent from start (from call NetworkTransport.Init) for all hosts.
GetOutgoingPacketCountForConnectionReturns how many packets have been sent for connection from it start (from call NetworkTransport.Connect for active connect or from connection request receiving for passive connect).
GetOutgoingPacketCountForHostReturns how many packets have been sent for host from it start (from call NetworkTransport.AddHost).
GetOutgoingPacketNetworkLossPercentReturns the value in percent of the number of sent packets that were dropped by the network and not received by the peer.
GetOutgoingPacketOverflowLossPercentReturns the value in percent of the number of sent packets that were dropped by the peer.
GetOutgoingSystemBytesCountReturns how much user payload and protocol system headers (in bytes) have been sent from start (from NetworkTransport.Init call).
GetOutgoingSystemBytesCountForConnectionReturns how much payload and protocol system headers (in bytes) have been sent from start for connection (from call NetworkTransport.Connect for active connect or from connection request receiving for passive connect).
GetOutgoingSystemBytesCountForHostReturns how much payload and protocol system headers (in bytes) have been sent from start for the host (from call NetworkTransport.AddHost).
GetOutgoingUserBytesCountReturns how much payload (user) bytes have been sent from start (from NetworkTransport.Init call).
GetOutgoingUserBytesCountForConnectionReturns how much payload (user) bytes have been sent from start for connection (from call NetworkTransport.Connect for active connect or from connection request receiving for passive connect).
GetOutgoingUserBytesCountForHostReturns how much payload (user) bytes have been sent from start for the host (from call NetworkTransport.AddHost).
GetRemoteDelayTimeMSReturns the delay for the timestamp received.
InitInitializes the NetworkTransport. Should be called before any other operations on the NetworkTransport are done.
IsBroadcastDiscoveryRunningCheck if the broadcast discovery sender is running.
NotifyWhenConnectionReadyForSendThis method allows you to specify that notifications callbacks should be called when Unity's networking can send more messages than defined in notificationLevel.
QueueMessageForSendingFunction is queueing but not sending messages.
ReceiveCalled to poll the underlying system for events.
ReceiveFromHostSimilar to NetworkTransport.Receive but will only poll for the provided hostId.
ReceiveRelayEventFromHostPolls the host for the following events: NetworkEventType.ConnectEvent and NetworkEventType.DisconnectEvent. Can only be called by the relay group owner.
RemoveHostCloses the opened socket, and closes all connections belonging to that socket.
SendSend data to peer.
SendMulticastAdd a connection for the multicast send.
SendQueuedMessagesSends messages, previously queued by NetworkTransport.QueueMessageForSending function.
SetBroadcastCredentialsSets the credentials required for receiving broadcast messages. Should any credentials of a received broadcast message not match, the broadcast discovery message is dropped.
SetPacketStatUsed to inform the profiler of network packet statistics.
ShutdownShut down the NetworkTransport.
StartBroadcastDiscoveryStarts sending a broadcasting message in all local subnets.
StartSendMulticastStart to multicast send.
StopBroadcastDiscoveryStop sending the broadcast discovery message.

Did you find this page useful? Please give it a rating: