Select your preferred scripting language. All code snippets will be displayed in this language.
class in UnityEngine.Networking
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.
CloseFor 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.
CloseThe 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.
connections | A read-only list of the current connections being managed. |
handlers | The message handler functions that are registered. |
hostTopology | The transport layer host-topology that the server is configured with. |
listenPort | The network port that the server is listening on. |
messageBuffer | The 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. |
messageReader | A NetworkReader object that is bound to the server's messageBuffer. |
networkConnectionClass | The type of class to be created for new network connections from clients. |
serverHostId | The transport layer hostId of the server. |
useWebSockets | This causes the server to listen for WebSocket connections instead of regular transport layer connections. |
ClearHandlers | Clears the message handlers that are registered. |
Configure | This configures the network transport layer of the server. |
Disconnect | This disconnects the connection of the corresponding connection id. |
DisconnectAllConnections | This disconnects all of the active connections. |
FindConnection | This looks up the network connection object for the specified connection Id. |
Initialize | Initialization function that is invoked when the server starts listening. This can be overridden to perform custom initialization such as setting the NetworkConnectionClass. |
Listen | This starts the server listening for connections on the specified port. |
ListenRelay | Starts 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. |
OnConnected | This virtual function can be overridden to perform custom functionality for new network connections. |
OnConnectError | A virtual function that is invoked when there is a connection error. |
OnData | This virtual function can be overridden to perform custom functionality when data is received for a connection. |
OnDataError | A virtual function that is called when a data error occurs on a connection. |
OnDisconnected | This virtual function can be overridden to perform custom functionality for disconnected network connections. |
OnDisconnectError | A virtual function that is called when a disconnect error happens. |
RegisterHandler | This registers a handler function for a message Id. |
RemoveConnectionAtIndex | This removes a connection object from the server's list of connections. |
SendBytesTo | This sends the data in an array of bytes to the connected client. |
SendWriterTo | This sends the contents of a NetworkWriter object to the connected client. |
SetConnectionAtIndex | This adds a connection created by external code to the server's list of connections, at the connection's connectionId index. |
SetNetworkConnectionClass | This sets the class that is used when creating new network connections. |
Stop | This stops a server from listening. |
UnregisterHandler | This unregisters a registered message handler function. |
Update | This function pumps the server causing incoming network data to be processed, and pending outgoing data to be sent. |
UpdateConnections | This function causes pending outgoing data on connections to be sent, but unlike Update() it works when the server is not listening. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thanks for helping to make the Unity documentation better!