2012-09-10 00:36:22 +08:00
|
|
|
#region MIT License
|
2013-01-11 19:32:38 +08:00
|
|
|
/*
|
2012-09-10 00:36:22 +08:00
|
|
|
* HttpServer.cs
|
|
|
|
*
|
|
|
|
* The MIT License
|
|
|
|
*
|
2013-01-28 18:42:47 +08:00
|
|
|
* Copyright (c) 2012-2013 sta.blockhead
|
2012-09-10 00:36:22 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
2012-11-02 16:55:00 +08:00
|
|
|
using System.Collections.Generic;
|
2012-09-10 00:36:22 +08:00
|
|
|
using System.Configuration;
|
2012-10-22 13:58:43 +08:00
|
|
|
using System.Diagnostics;
|
2012-09-10 00:36:22 +08:00
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
|
|
|
using WebSocketSharp.Net;
|
|
|
|
|
|
|
|
namespace WebSocketSharp.Server {
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Provides the functions of a simple HTTP server that allows to accept the WebSocket connection requests.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para>
|
|
|
|
/// The HttpServer class provides the multi WebSocket service.
|
|
|
|
/// </para>
|
|
|
|
/// <para>
|
|
|
|
/// <para>
|
|
|
|
/// The HttpServer class needs the application configuration file to configure the server root path.
|
|
|
|
/// </para>
|
|
|
|
/// <code lang="xml">
|
|
|
|
/// <?xml version="1.0" encoding="utf-8"?>
|
|
|
|
/// <configuration>
|
|
|
|
/// <appSettings>
|
|
|
|
/// <add key="RootPath" value="./Public" />
|
|
|
|
/// </appSettings>
|
|
|
|
/// </configuration>
|
|
|
|
/// </code>
|
|
|
|
/// </para>
|
|
|
|
/// </remarks>
|
2012-09-19 13:40:12 +08:00
|
|
|
public class HttpServer {
|
|
|
|
|
2012-09-10 00:36:22 +08:00
|
|
|
#region Fields
|
|
|
|
|
2013-01-28 18:42:47 +08:00
|
|
|
private bool _isWindows;
|
|
|
|
private HttpListener _listener;
|
|
|
|
private int _port;
|
2013-02-11 21:57:01 +08:00
|
|
|
private Thread _receiveRequestThread;
|
2013-01-28 18:42:47 +08:00
|
|
|
private string _rootPath;
|
|
|
|
private ServiceHostManager _svcHosts;
|
2012-09-10 00:36:22 +08:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="HttpServer"/> class that listens for incoming requests
|
|
|
|
/// on port 80.
|
|
|
|
/// </summary>
|
2012-09-10 00:36:22 +08:00
|
|
|
public HttpServer()
|
|
|
|
: this(80)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="HttpServer"/> class that listens for incoming requests
|
|
|
|
/// on the specified <paramref name="port"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="port">
|
|
|
|
/// An <see cref="int"/> that contains a port number.
|
|
|
|
/// </param>
|
2012-09-10 00:36:22 +08:00
|
|
|
public HttpServer(int port)
|
|
|
|
{
|
2012-09-19 13:40:12 +08:00
|
|
|
_port = port;
|
2012-09-13 10:18:52 +08:00
|
|
|
init();
|
2012-09-10 00:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2012-10-26 13:58:50 +08:00
|
|
|
#region Properties
|
2012-09-10 00:36:22 +08:00
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the port on which to listen for incoming requests.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>
|
|
|
|
/// An <see cref="int"/> that contains a port number.
|
|
|
|
/// </value>
|
2012-09-10 00:36:22 +08:00
|
|
|
public int Port {
|
|
|
|
get { return _port; }
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the collection of paths associated with the every WebSocket services that the server provides.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>
|
|
|
|
/// An IEnumerable<string> that contains the collection of paths.
|
|
|
|
/// </value>
|
2013-01-28 18:42:47 +08:00
|
|
|
public IEnumerable<string> ServicePaths {
|
2012-11-02 16:55:00 +08:00
|
|
|
get {
|
2013-01-28 18:42:47 +08:00
|
|
|
return _svcHosts.Paths;
|
2012-11-02 16:55:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether the server cleans up the inactive WebSocket service instances periodically.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>
|
|
|
|
/// <c>true</c> if the server cleans up the inactive WebSocket service instances every 60 seconds;
|
|
|
|
/// otherwise, <c>false</c>. The default value is <c>true</c>.
|
|
|
|
/// </value>
|
2012-10-26 13:58:50 +08:00
|
|
|
public bool Sweeped {
|
|
|
|
get {
|
2013-01-28 18:42:47 +08:00
|
|
|
return _svcHosts.Sweeped;
|
2012-10-26 13:58:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set {
|
2013-01-28 18:42:47 +08:00
|
|
|
_svcHosts.Sweeped = value;
|
2012-10-26 13:58:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 00:36:22 +08:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server gets an error.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ErrorEventArgs> OnError;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP CONNECT request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToConnect;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP DELETE request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToDelete;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP GET request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToGet;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP HEAD request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToHead;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP OPTIONS request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToOptions;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP PATCH request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToPatch;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP POST request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToPost;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP PUT request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToPut;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the server receives an HTTP TRACE request.
|
|
|
|
/// </summary>
|
|
|
|
public event EventHandler<ResponseEventArgs> OnResponseToTrace;
|
2012-09-10 00:36:22 +08:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Private Methods
|
|
|
|
|
2012-09-11 12:21:47 +08:00
|
|
|
private void configureFromConfigFile()
|
|
|
|
{
|
|
|
|
_rootPath = ConfigurationManager.AppSettings["RootPath"];
|
|
|
|
}
|
|
|
|
|
2012-09-13 10:18:52 +08:00
|
|
|
private void init()
|
|
|
|
{
|
|
|
|
_isWindows = false;
|
|
|
|
_listener = new HttpListener();
|
2013-01-28 18:42:47 +08:00
|
|
|
_svcHosts = new ServiceHostManager();
|
2012-09-13 10:18:52 +08:00
|
|
|
|
|
|
|
var os = Environment.OSVersion;
|
|
|
|
if (os.Platform != PlatformID.Unix && os.Platform != PlatformID.MacOSX)
|
|
|
|
_isWindows = true;
|
|
|
|
|
|
|
|
var prefix = String.Format(
|
|
|
|
"http{0}://*:{1}/", _port == 443 ? "s" : String.Empty, _port);
|
|
|
|
_listener.Prefixes.Add(prefix);
|
|
|
|
|
|
|
|
configureFromConfigFile();
|
|
|
|
}
|
|
|
|
|
2012-09-12 11:29:42 +08:00
|
|
|
private bool isUpgrade(HttpListenerRequest request, string value)
|
|
|
|
{
|
|
|
|
if (!request.Headers.Exists("Upgrade", value))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!request.Headers.Exists("Connection", "Upgrade"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-22 13:58:43 +08:00
|
|
|
private void onError(string message)
|
2012-09-10 00:36:22 +08:00
|
|
|
{
|
2012-10-22 13:58:43 +08:00
|
|
|
#if DEBUG
|
|
|
|
var callerFrame = new StackFrame(1);
|
|
|
|
var caller = callerFrame.GetMethod();
|
|
|
|
Console.WriteLine("HTTPSV: Error@{0}: {1}", caller.Name, message);
|
|
|
|
#endif
|
|
|
|
OnError.Emit(this, new ErrorEventArgs(message));
|
2012-09-10 00:36:22 +08:00
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
private void receiveRequest()
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var context = _listener.GetContext();
|
|
|
|
respondAsync(context);
|
|
|
|
}
|
|
|
|
catch (HttpListenerException)
|
|
|
|
{
|
|
|
|
// HttpListener has been closed.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
onError(ex.Message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-22 13:58:43 +08:00
|
|
|
private void respond(HttpListenerContext context)
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
|
|
|
var req = context.Request;
|
|
|
|
var res = context.Response;
|
|
|
|
var eventArgs = new ResponseEventArgs(context);
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "GET" && !OnResponseToGet.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToGet(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "HEAD" && !OnResponseToHead.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToHead(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "POST" && !OnResponseToPost.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToPost(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "PUT" && !OnResponseToPut.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToPut(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "DELETE" && !OnResponseToDelete.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToDelete(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "OPTIONS" && !OnResponseToOptions.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToOptions(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "TRACE" && !OnResponseToTrace.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToTrace(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "CONNECT" && !OnResponseToConnect.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToConnect(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
if (req.HttpMethod == "PATCH" && !OnResponseToPatch.IsNull())
|
2012-09-11 12:21:47 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
OnResponseToPatch(this, eventArgs);
|
2012-09-11 12:21:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res.StatusCode = (int)HttpStatusCode.NotImplemented;
|
|
|
|
}
|
|
|
|
|
2012-10-22 13:58:43 +08:00
|
|
|
private void respondAsync(HttpListenerContext context)
|
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
WaitCallback callback = (state) =>
|
2012-10-22 13:58:43 +08:00
|
|
|
{
|
|
|
|
var req = context.Request;
|
|
|
|
var res = context.Response;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (isUpgrade(req, "websocket"))
|
|
|
|
{
|
|
|
|
if (upgradeToWebSocket(context))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
respond(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Close();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
onError(ex.Message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
ThreadPool.QueueUserWorkItem(callback);
|
2012-10-22 13:58:43 +08:00
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
private void startReceiveRequestThread()
|
2012-09-10 00:36:22 +08:00
|
|
|
{
|
2013-02-11 21:57:01 +08:00
|
|
|
_receiveRequestThread = new Thread(new ThreadStart(receiveRequest));
|
|
|
|
_receiveRequestThread.IsBackground = true;
|
|
|
|
_receiveRequestThread.Start();
|
2012-09-10 00:36:22 +08:00
|
|
|
}
|
|
|
|
|
2012-09-19 13:40:12 +08:00
|
|
|
private bool upgradeToWebSocket(HttpListenerContext context)
|
2012-09-10 00:36:22 +08:00
|
|
|
{
|
2012-10-22 13:58:43 +08:00
|
|
|
var res = context.Response;
|
|
|
|
var wsContext = context.AcceptWebSocket();
|
2012-10-23 14:39:31 +08:00
|
|
|
var socket = wsContext.WebSocket;
|
2012-10-22 13:58:43 +08:00
|
|
|
var path = wsContext.Path.UrlDecode();
|
2012-10-23 14:39:31 +08:00
|
|
|
|
|
|
|
IServiceHost svcHost;
|
2013-01-28 18:42:47 +08:00
|
|
|
if (!_svcHosts.TryGetServiceHost(path, out svcHost))
|
2012-09-20 19:28:49 +08:00
|
|
|
{
|
|
|
|
res.StatusCode = (int)HttpStatusCode.NotImplemented;
|
2012-09-19 13:40:12 +08:00
|
|
|
return false;
|
2012-09-20 19:28:49 +08:00
|
|
|
}
|
2012-09-19 13:40:12 +08:00
|
|
|
|
2012-10-23 14:39:31 +08:00
|
|
|
svcHost.BindWebSocket(socket);
|
2012-09-19 13:40:12 +08:00
|
|
|
return true;
|
2012-09-10 00:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public Methods
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Adds the specified type WebSocket service.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="absPath">
|
|
|
|
/// A <see cref="string"/> that contains an absolute path associated with the WebSocket service.
|
|
|
|
/// </param>
|
|
|
|
/// <typeparam name="T">
|
|
|
|
/// The type of the WebSocket service. The T must inherit the <see cref="WebSocketService"/> class.
|
|
|
|
/// </typeparam>
|
|
|
|
public void AddWebSocketService<T>(string absPath)
|
2012-09-19 13:40:12 +08:00
|
|
|
where T : WebSocketService, new()
|
|
|
|
{
|
2012-10-22 13:58:43 +08:00
|
|
|
string msg;
|
|
|
|
if (!absPath.IsValidAbsolutePath(out msg))
|
|
|
|
{
|
|
|
|
onError(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:39:31 +08:00
|
|
|
var svcHost = new WebSocketServiceHost<T>();
|
2012-11-02 16:55:00 +08:00
|
|
|
svcHost.Uri = absPath.ToUri();
|
|
|
|
if (!Sweeped)
|
|
|
|
svcHost.Sweeped = Sweeped;
|
|
|
|
|
2013-01-28 18:42:47 +08:00
|
|
|
_svcHosts.Add(absPath, svcHost);
|
2012-09-19 13:40:12 +08:00
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the contents of the specified file.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>
|
|
|
|
/// An array of <see cref="byte"/> that contains the contents of the file.
|
|
|
|
/// </returns>
|
|
|
|
/// <param name="path">
|
|
|
|
/// A <see cref="string"/> that contains a virtual path to the file to get.
|
|
|
|
/// </param>
|
2012-09-10 00:36:22 +08:00
|
|
|
public byte[] GetFile(string path)
|
|
|
|
{
|
|
|
|
var filePath = _rootPath + path;
|
2012-09-13 10:18:52 +08:00
|
|
|
if (_isWindows)
|
2012-09-12 21:52:02 +08:00
|
|
|
filePath = filePath.Replace("/", "\\");
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
return File.Exists(filePath)
|
|
|
|
? File.ReadAllBytes(filePath)
|
|
|
|
: null;
|
2012-09-10 00:36:22 +08:00
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Starts to receive incoming requests.
|
|
|
|
/// </summary>
|
2012-09-10 00:36:22 +08:00
|
|
|
public void Start()
|
|
|
|
{
|
|
|
|
_listener.Start();
|
2013-02-11 21:57:01 +08:00
|
|
|
startReceiveRequestThread();
|
2012-09-10 00:36:22 +08:00
|
|
|
}
|
|
|
|
|
2013-02-11 21:57:01 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Stops receiving incoming requests.
|
|
|
|
/// </summary>
|
2012-09-10 00:36:22 +08:00
|
|
|
public void Stop()
|
|
|
|
{
|
|
|
|
_listener.Close();
|
2013-02-11 21:57:01 +08:00
|
|
|
_receiveRequestThread.Join(5 * 1000);
|
2013-01-28 18:42:47 +08:00
|
|
|
_svcHosts.Stop();
|
2012-09-10 00:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|