Fix due to the renamed WebSocketServer<T> to WebSocketServiceHost<T>

This commit is contained in:
sta
2012-10-23 15:39:31 +09:00
parent c55b5d6479
commit 2ae1d35d03
38 changed files with 387 additions and 249 deletions

View File

@@ -2,7 +2,7 @@
/**
* WebSocketServer.cs
*
* A C# implementation of a WebSocket protocol server.
* A C# implementation of the WebSocket protocol server.
*
* The MIT License
*
@@ -29,10 +29,8 @@
#endregion
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using WebSocketSharp.Net;
using WebSocketSharp.Net.Sockets;
namespace WebSocketSharp.Server {
@@ -40,7 +38,7 @@ namespace WebSocketSharp.Server {
{
#region Field
private Dictionary<string, IServiceHost> _services;
private ServiceManager _services;
#endregion
@@ -80,7 +78,7 @@ namespace WebSocketSharp.Server {
private void init()
{
_services = new Dictionary<string, IServiceHost>();
_services = new ServiceManager();
}
#endregion
@@ -92,7 +90,9 @@ namespace WebSocketSharp.Server {
var context = client.AcceptWebSocket();
var socket = context.WebSocket;
var path = context.Path.UrlDecode();
if (!_services.ContainsKey(path))
IServiceHost svcHost;
if (!_services.TryGetServiceHost(path, out svcHost))
{
socket.Close(HttpStatusCode.NotImplemented);
return;
@@ -101,8 +101,7 @@ namespace WebSocketSharp.Server {
if (BaseUri.IsAbsoluteUri)
socket.Url = new Uri(BaseUri, path);
var service = _services[path];
service.BindWebSocket(socket);
svcHost.BindWebSocket(socket);
}
#endregion
@@ -119,118 +118,19 @@ namespace WebSocketSharp.Server {
return;
}
var service = new WebSocketServer<T>();
_services.Add(absPath, service);
var svcHost = new WebSocketServiceHost<T>();
_services.Add(absPath, svcHost);
}
public void Broadcast(string data)
{
_services.Broadcast(data);
}
public override void Stop()
{
base.Stop();
foreach (var service in _services.Values)
service.Stop();
_services.Clear();
}
#endregion
}
public class WebSocketServer<T> : WebSocketServerBase, IServiceHost
where T : WebSocketService, new()
{
#region Fields
private SessionManager _sessions;
#endregion
#region Internal Constructor
internal WebSocketServer()
{
init();
}
#endregion
#region Public Constructors
public WebSocketServer(int port)
: this(port, "/")
{
}
public WebSocketServer(string url)
: base(url)
{
init();
}
public WebSocketServer(int port, string absPath)
: this(System.Net.IPAddress.Any, port, absPath)
{
}
public WebSocketServer(System.Net.IPAddress address, int port, string absPath)
: base(address, port, absPath)
{
init();
}
#endregion
#region Property
public Uri Uri {
get {
return BaseUri;
}
}
#endregion
#region Private Method
private void init()
{
_sessions = new SessionManager();
}
#endregion
#region Protected Method
protected override void AcceptWebSocket(TcpClient client)
{
var context = client.AcceptWebSocket();
var socket = context.WebSocket;
var path = context.Path.UrlDecode();
if (path != Uri.GetAbsolutePath().UrlDecode())
{
socket.Close(HttpStatusCode.NotImplemented);
return;
}
if (Uri.IsAbsoluteUri)
socket.Url = new Uri(Uri, path);
BindWebSocket(socket);
}
#endregion
#region Public Methods
public void BindWebSocket(WebSocket socket)
{
T service = new T();
service.Bind(socket, _sessions);
service.Start();
}
public override void Stop()
{
base.Stop();
_sessions.Stop();
_services.Stop();
}
#endregion