Version: 5.3 (switch to 5.4b)
ЯзыкEnglish
  • C#
  • JS

Язык программирования

Выберите подходящий для вас язык программирования. Все примеры кода будут представлены на выбранном языке.

NetworkServerSimple

class in UnityEngine.Networking

Предложить изменения

Успех!

Благодарим вас за то, что вы помогаете нам улучшить качество документации по Unity. Однако, мы не можем принять любой перевод. Мы проверяем каждый предложенный вами вариант перевода и принимаем его только если он соответствует оригиналу.

Закрыть

Ошибка внесения изменений

По определённым причинам предложенный вами перевод не может быть принят. Пожалуйста <a>попробуйте снова</a> через пару минут. И выражаем вам свою благодарность за то, что вы уделяете время, чтобы улучшить документацию по Unity.

Закрыть

Отменить

Руководство

Описание

The NetworkServerSimple is a basic server class without the "game" related functionality that the NetworkServer class has.

This class has no scene management, spawning, player objects, observers, or static interface like the NetworkServer class. It is simply a server that listens on a port, manages connections, and handles messages. There can be more than one instance of this class in a process.

Like the NetworkServer and NetworkClient classes, it allows the type of NetworkConnection class created for new connections to be specified with SetNetworkConnectionClass(), so custom types of network connections can be used with it.

This class can be used by overriding the virtual functions OnConnected, OnDisconnected and OnData; or by registering message handlers.

Переменные

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.

Открытые функции

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.
SetNetworkConnectionClassThis sets the class that is used when creating new network connections.
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.