Class HttpHostingService
HTTP implemenation of hosting service.
Inherited Members
Namespace: UnityEditor.AddressableAssets.HostingServices
Syntax
public class HttpHostingService : BaseHostingService, IHostingService
Constructors
HttpHostingService()
Create a new HttpHostingService
Declaration
public HttpHostingService()
Properties
HostingServiceContentRoots
List of content roots for hosting service.
Declaration
public override List<string> HostingServiceContentRoots { get; }
Property Value
| Type | Description |
|---|---|
| List<String> |
Overrides
HostingServicePort
The port number on which the service is listening
Declaration
public int HostingServicePort { get; protected set; }
Property Value
| Type | Description |
|---|---|
| Int32 |
IsHostingServiceRunning
Gets the current running status of the hosting service.
Declaration
public override bool IsHostingServiceRunning { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Overrides
MyHttpListener
The actual Http listener used by this service
Declaration
protected HttpListener MyHttpListener { get; set; }
Property Value
| Type | Description |
|---|---|
| HttpListener |
ProfileVariables
Dictionary of profile variables defined by the hosting service.
Declaration
public override Dictionary<string, string> ProfileVariables { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<String, String> |
Overrides
Methods
ConfigureHttpListener()
Handles any configuration necessary for MyHttpListener before listening for connections.
Declaration
protected virtual void ConfigureHttpListener()
FindFileInContentRoots(String)
Searches for the given relative path within the configured content root directores.
Declaration
protected virtual string FindFileInContentRoots(string relativePath)
Parameters
| Type | Name | Description |
|---|---|---|
| String | relativePath |
Returns
| Type | Description |
|---|---|
| String | The full system path to the file if found, or null if file could not be found |
GetAvailablePort()
Find an open network listen port on the local system
Declaration
protected static int GetAvailablePort()
Returns
| Type | Description |
|---|---|
| Int32 | a system assigned port, or 0 if none are available |
HandleRequest(IAsyncResult)
Asynchronous callback to handle a client connection request on MyHttpListener. This method is recursive in that it will call itself immediately after receiving a new incoming request to listen for the next connection.
Declaration
protected virtual void HandleRequest(IAsyncResult ar)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncResult | ar | Asynchronous result from previous request. Pass null to listen for an initial request |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | thrown when the request result code is unknown |
IsPortAvailable(Int32)
Tests to see if the given port # is already in use
Declaration
protected static bool IsPortAvailable(int port)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | port | port number to test |
Returns
| Type | Description |
|---|---|
| Boolean | true if there is not a listener on the port |
OnAfterDeserialize(KeyDataStore)
Called immediatley following a domain reload by the HostingServicesManager, for restoring state information after the service is recreated.
Declaration
public override void OnAfterDeserialize(KeyDataStore dataStore)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyDataStore | dataStore | A key/value pair data store for use in restoring state information |
Overrides
OnBeforeSerialize(KeyDataStore)
Called by the HostingServicesManager before a domain reload, giving the hosting service an opportunity to persist state information.
Declaration
public override void OnBeforeSerialize(KeyDataStore dataStore)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyDataStore | dataStore | A key/value pair data store for use in persisting state information |
Overrides
OnGUI()
Render the hosting service GUI.
Declaration
public override void OnGUI()
Overrides
ResetListenPort(Int32)
Listen on a new port then next time the server starts. If the server is already running, it will be stopped and restarted automatically.
Declaration
public void ResetListenPort(int port = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | port | Specify a port to listen on. Default is 0 to choose any open port |
Return404(HttpListenerContext)
Sets the status code to 404 on the given
Declaration
protected virtual void Return404(HttpListenerContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpListenerContext | context |
ReturnFile(HttpListenerContext, String, Int32)
Sends a file to the connected HTTP client
Declaration
protected virtual void ReturnFile(HttpListenerContext context, string filePath, int readBufferSize = 65536)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpListenerContext | context | |
| String | filePath | |
| Int32 | readBufferSize |
StartHostingService()
Starts the hosting service.
Declaration
public override void StartHostingService()
Overrides
StopHostingService()
Stops the hosting service.
Declaration
public override void StopHostingService()