Version: 5.4 (switch to 5.5b)
言語English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NetworkServerSimple

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

Sumbission failed

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

Close

Cancel

マニュアルに切り替える

Description

NetworkServerSimple は NetworkServer クラスが持つ "ゲーム" に関連した機能がないサーバーの基本クラスです。

このクラスにはシーン管理、スポーン(spawn)、プレーヤーオブジェクト、オブザーバーや NetworkServer のクラスのような静的なインターフェースはありません。単にポートのリッスン、接続管理、メッセージを処理するサーバーです。プロセス内にこのクラスの複数のインスタンスがあります。

NetworkServer と NetworkClient のクラスのように、 SetNetworkConnectionClass() で指定される新しい接続のために NetworkConnection クラスの型が作成され、ネットワーク接続のカスタムの型を使用できるようにします。

このクラスは OnConnected、OnDisconnected、OnData の仮想関数をオーバーライドするかメッセージハンドラーを登録することにより使用できます。

Variables

connectionsA read-only list of the current connections being managed.
handlersThe message handler functions that are registered.
hostTopologyThe transport layer host-topology that the server is configured with.
listenPortThe network port that the server is listening on.
messageBufferThe internal buffer that the server reads data from the network into. This will contain the most recent data read from the network when OnData() is called.
messageReaderA NetworkReader object that is bound to the server's messageBuffer.
networkConnectionClassThe type of class to be created for new network connections from clients.
serverHostIdThe transport layer hostId of the server.
useWebSocketsThis causes the server to listen for WebSocket connections instead of regular transport layer connections.

Public Functions

ClearHandlersClears the message handlers that are registered.
ConfigureThis configures the network transport layer of the server.
DisconnectThis disconnects the connection of the corresponding connection id.
DisconnectAllConnectionsThis disconnects all of the active connections.
FindConnectionThis looks up the network connection object for the specified connection Id.
InitializeInitialization function that is invoked when the server starts listening. This can be overridden to perform custom initialization such as setting the NetworkConnectionClass.
ListenThis starts the server listening for connections on the specified port.
ListenRelayStarts a server using a Relay server. This is the manual way of using the Relay server, as the regular NetworkServer.Connect() will automatically use the Relay server if a match exists.
OnConnectedThis virtual function can be overridden to perform custom functionality for new network connections.
OnConnectErrorA virtual function that is invoked when there is a connection error.
OnDataThis virtual function can be overridden to perform custom functionality when data is received for a connection.
OnDataErrorA virtual function that is called when a data error occurs on a connection.
OnDisconnectedThis virtual function can be overridden to perform custom functionality for disconnected network connections.
OnDisconnectErrorA virtual function that is called when a disconnect error happens.
RegisterHandlerThis registers a handler function for a message Id.
RemoveConnectionAtIndexThis removes a connection object from the server's list of connections.
SendBytesToThis sends the data in an array of bytes to the connected client.
SendWriterToThis sends the contents of a NetworkWriter object to the connected client.
SetConnectionAtIndexThis adds a connection created by external code to the server's list of connections, at the connection's connectionId index.
SetNetworkConnectionClass新しいネットワーク接続を作成したものをこのクラスに設定します。
StopThis stops a server from listening.
UnregisterHandlerThis unregisters a registered message handler function.
UpdateThis function pumps the server causing incoming network data to be processed, and pending outgoing data to be sent.
UpdateConnectionsThis function causes pending outgoing data on connections to be sent, but unlike Update() it works when the server is not listening.