Fix due to the removed HttpServer<T> class from HttpServer.cs
This commit is contained in:
@@ -169,9 +169,9 @@ namespace WebSocketSharp.Net {
|
||||
|
||||
#region Public Method
|
||||
|
||||
public HttpListenerWebSocketContext AcceptWebSocket ()
|
||||
public HttpListenerWebSocketContext AcceptWebSocket (string path)
|
||||
{
|
||||
return new HttpListenerWebSocketContext (this);
|
||||
return new HttpListenerWebSocketContext (path, this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@@ -40,10 +40,10 @@ namespace WebSocketSharp.Net {
|
||||
private HttpListenerContext _context;
|
||||
private WebSocket _socket;
|
||||
|
||||
internal HttpListenerWebSocketContext(HttpListenerContext context)
|
||||
internal HttpListenerWebSocketContext(string path, HttpListenerContext context)
|
||||
{
|
||||
_context = context;
|
||||
_socket = new WebSocket(this);
|
||||
_socket = new WebSocket(path.ToUri(), this);
|
||||
}
|
||||
|
||||
internal HttpListenerContext BaseContext {
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -34,18 +35,16 @@ using WebSocketSharp.Net;
|
||||
|
||||
namespace WebSocketSharp.Server {
|
||||
|
||||
public class HttpServer<T>
|
||||
where T : WebSocketService, new()
|
||||
{
|
||||
public class HttpServer {
|
||||
|
||||
#region Fields
|
||||
|
||||
private Thread _acceptRequestThread;
|
||||
private bool _isWindows;
|
||||
private HttpListener _listener;
|
||||
private int _port;
|
||||
private string _rootPath;
|
||||
private Uri _wsPath;
|
||||
private WebSocketServer<T> _wsServer;
|
||||
private Thread _acceptRequestThread;
|
||||
private bool _isWindows;
|
||||
private HttpListener _listener;
|
||||
private int _port;
|
||||
private string _rootPath;
|
||||
private Dictionary<string, IWebSocketServer> _wsServers;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -57,14 +56,8 @@ namespace WebSocketSharp.Server {
|
||||
}
|
||||
|
||||
public HttpServer(int port)
|
||||
: this(port, "/")
|
||||
{
|
||||
}
|
||||
|
||||
public HttpServer(int port, string wsPath)
|
||||
{
|
||||
_port = port;
|
||||
_wsPath = wsPath.ToUri();
|
||||
_port = port;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -126,7 +119,7 @@ namespace WebSocketSharp.Server {
|
||||
{
|
||||
_isWindows = false;
|
||||
_listener = new HttpListener();
|
||||
_wsServer = new WebSocketServer<T>();
|
||||
_wsServers = new Dictionary<string, IWebSocketServer>();
|
||||
|
||||
var os = Environment.OSVersion;
|
||||
if (os.Platform != PlatformID.Unix && os.Platform != PlatformID.MacOSX)
|
||||
@@ -163,11 +156,15 @@ namespace WebSocketSharp.Server {
|
||||
{
|
||||
if (req.IsWebSocketRequest)
|
||||
{
|
||||
upgradeToWebSocket(context);
|
||||
return;
|
||||
}
|
||||
if (upgradeToWebSocket(context))
|
||||
return;
|
||||
|
||||
res.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
res.StatusCode = (int)HttpStatusCode.NotImplemented;
|
||||
}
|
||||
else
|
||||
{
|
||||
res.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -254,19 +251,31 @@ namespace WebSocketSharp.Server {
|
||||
_acceptRequestThread.Start();
|
||||
}
|
||||
|
||||
private void upgradeToWebSocket(HttpListenerContext context)
|
||||
private bool upgradeToWebSocket(HttpListenerContext context)
|
||||
{
|
||||
var wsContext = context.AcceptWebSocket();
|
||||
var path = context.Request.RawUrl;
|
||||
if (!_wsServers.ContainsKey(path))
|
||||
return false;
|
||||
|
||||
var wsContext = context.AcceptWebSocket(path);
|
||||
var socket = wsContext.WebSocket;
|
||||
if (_wsPath.ToString() != "/")
|
||||
socket.Url = _wsPath;
|
||||
_wsServer.BindWebSocket(socket);
|
||||
var wsServer = _wsServers[path];
|
||||
wsServer.BindWebSocket(socket);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddService<T>(string path)
|
||||
where T : WebSocketService, new()
|
||||
{
|
||||
var server = new WebSocketServer<T>();
|
||||
_wsServers.Add(path, server);
|
||||
}
|
||||
|
||||
public byte[] GetFile(string path)
|
||||
{
|
||||
var filePath = _rootPath + path;
|
||||
@@ -289,7 +298,8 @@ namespace WebSocketSharp.Server {
|
||||
{
|
||||
_listener.Close();
|
||||
_acceptRequestThread.Join(5 * 1000);
|
||||
_wsServer.StopServices();
|
||||
foreach (var server in _wsServers.Values)
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
40
websocket-sharp/Server/IWebSocketServer.cs
Normal file
40
websocket-sharp/Server/IWebSocketServer.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
#region MIT License
|
||||
/**
|
||||
* IWebSocketServer.cs
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2012 sta.blockhead
|
||||
*
|
||||
* 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;
|
||||
|
||||
namespace WebSocketSharp.Server {
|
||||
|
||||
public interface IWebSocketServer {
|
||||
|
||||
void BindWebSocket(WebSocket socket);
|
||||
void Start();
|
||||
void Stop();
|
||||
void StopServices();
|
||||
}
|
||||
}
|
@@ -39,7 +39,7 @@ using WebSocketSharp.Frame;
|
||||
|
||||
namespace WebSocketSharp.Server {
|
||||
|
||||
public class WebSocketServer<T>
|
||||
public class WebSocketServer<T> : IWebSocketServer
|
||||
where T : WebSocketService, new()
|
||||
{
|
||||
#region Fields
|
||||
|
@@ -106,10 +106,10 @@ namespace WebSocketSharp
|
||||
|
||||
#region Internal Constructor
|
||||
|
||||
internal WebSocket(HttpListenerWebSocketContext context)
|
||||
internal WebSocket(Uri uri, HttpListenerWebSocketContext context)
|
||||
: this()
|
||||
{
|
||||
_uri = new Uri("/", UriKind.Relative);
|
||||
_uri = uri;
|
||||
_context = context;
|
||||
_isClient = false;
|
||||
_isSecure = _context.IsSecureConnection;
|
||||
@@ -356,14 +356,11 @@ namespace WebSocketSharp
|
||||
{
|
||||
if (send(frame) && !Thread.CurrentThread.IsBackground)
|
||||
{
|
||||
if (_isClient)
|
||||
{
|
||||
if (_isClient && _msgThread != null)
|
||||
_msgThread.Join(5 * 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (!_isClient && _exitedMessageLoop != null)
|
||||
_exitedMessageLoop.WaitOne(5 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
ReadyState = WsState.CLOSED;
|
||||
@@ -880,15 +877,21 @@ namespace WebSocketSharp
|
||||
{
|
||||
if (_unTransmittedBuffer.Count == 0)
|
||||
{
|
||||
_wsStream.WriteFrame(frame);
|
||||
if (_wsStream != null)
|
||||
{
|
||||
_wsStream.WriteFrame(frame);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (_unTransmittedBuffer.Count > 0)
|
||||
{
|
||||
_unTransmittedBuffer.Add(frame);
|
||||
var msg = "Current data can not be sent because there is untransmitted data.";
|
||||
error(msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -896,8 +899,6 @@ namespace WebSocketSharp
|
||||
error(ex.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void send(Opcode opcode, PayloadData data)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -108,6 +108,7 @@
|
||||
<Compile Include="Server\ResponseEventArgs.cs" />
|
||||
<Compile Include="Net\HttpVersion.cs" />
|
||||
<Compile Include="Net\HttpStatusCode.cs" />
|
||||
<Compile Include="Server\IWebSocketServer.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user