Fix due to the modified WebSocketContext.cs

This commit is contained in:
sta
2013-02-26 11:39:59 +09:00
parent 8232c95cd8
commit 2e8a24a667
93 changed files with 1016 additions and 362 deletions

View File

@@ -353,7 +353,6 @@ namespace WebSocketSharp.Server {
{
var res = context.Response;
var wsContext = context.AcceptWebSocket();
var socket = wsContext.WebSocket;
var path = wsContext.Path.UrlDecode();
IServiceHost svcHost;
@@ -363,7 +362,7 @@ namespace WebSocketSharp.Server {
return false;
}
svcHost.BindWebSocket(socket);
svcHost.BindWebSocket(wsContext);
return true;
}

View File

@@ -27,11 +27,12 @@
#endregion
using System;
using WebSocketSharp.Net.WebSockets;
namespace WebSocketSharp.Server {
/// <summary>
/// Exposes the methods and property for the WebSocket service host.
/// Exposes the methods and property for the host that provides a <see cref="WebSocketService"/>.
/// </summary>
/// <remarks>
/// </remarks>
@@ -46,12 +47,12 @@ namespace WebSocketSharp.Server {
bool Sweeped { get; set; }
/// <summary>
/// Binds the specified <see cref="WebSocket"/> to the WebSocket service instance.
/// Binds the specified <see cref="WebSocketContext"/> to a <see cref="WebSocketService"/> instance.
/// </summary>
/// <param name="socket">
/// A <see cref="WebSocketSharp.WebSocket"/> to bind.
/// <param name="context">
/// A <see cref="WebSocketContext"/> that contains the WebSocket connection request objects to bind.
/// </param>
void BindWebSocket(WebSocket socket);
void BindWebSocket(WebSocketContext context);
/// <summary>
/// Broadcasts the specified <see cref="string"/> to all service clients.

View File

@@ -191,27 +191,27 @@ namespace WebSocketSharp.Server {
#region Protected Method
/// <summary>
/// Accepts a WebSocket connection.
/// Accepts a WebSocket connection request.
/// </summary>
/// <param name="context">
/// A <see cref="TcpListenerWebSocketContext"/> that contains the WebSocket connection request objects.
/// </param>
protected override void AcceptWebSocket(TcpListenerWebSocketContext context)
{
var socket = context.WebSocket;
var path = context.Path.UrlDecode();
var websocket = context.WebSocket;
var path = context.Path.UrlDecode();
IServiceHost svcHost;
if (!_svcHosts.TryGetServiceHost(path, out svcHost))
{
socket.Close(HttpStatusCode.NotImplemented);
websocket.Close(HttpStatusCode.NotImplemented);
return;
}
if (BaseUri.IsAbsoluteUri)
socket.Url = new Uri(BaseUri, path);
websocket.Url = new Uri(BaseUri, path);
svcHost.BindWebSocket(socket);
svcHost.BindWebSocket(context);
}
#endregion

View File

@@ -336,7 +336,7 @@ namespace WebSocketSharp.Server {
#region Protected Methods
/// <summary>
/// Accepts a WebSocket connection.
/// Accepts a WebSocket connection request.
/// </summary>
/// <param name="context">
/// A <see cref="TcpListenerWebSocketContext"/> that contains the WebSocket connection request objects.

View File

@@ -30,6 +30,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading;
using WebSocketSharp.Net.WebSockets;
namespace WebSocketSharp.Server {
@@ -43,8 +44,9 @@ namespace WebSocketSharp.Server {
#region Private Fields
private WebSocketContext _context;
private WebSocketServiceManager _sessions;
private WebSocket _socket;
private WebSocket _websocket;
#endregion
@@ -64,26 +66,30 @@ namespace WebSocketSharp.Server {
#region Protected Properties
/// <summary>
/// Gets the HTTP query string variables used in the WebSocket opening handshake.
/// Gets the collection of query string variables used in the WebSocket opening handshake.
/// </summary>
/// <value>
/// A <see cref="NameValueCollection"/> that contains the query string variables.
/// A <see cref="NameValueCollection"/> that contains the collection of query string variables.
/// </value>
protected NameValueCollection QueryString {
get {
return IsBound ? _socket.QueryString : null;
return IsBound
? _context.QueryString
: null;
}
}
/// <summary>
/// Gets the sessions to the WebSocket service.
/// Gets the sessions to the <see cref="WebSocketService"/>.
/// </summary>
/// <value>
/// A <see cref="WebSocketServiceManager"/> that contains the sessions to the WebSocket service.
/// A <see cref="WebSocketServiceManager"/> that contains the sessions to the the <see cref="WebSocketService"/>.
/// </value>
protected WebSocketServiceManager Sessions {
get {
return IsBound ? _sessions : null;
return IsBound
? _sessions
: null;
}
}
@@ -137,30 +143,31 @@ namespace WebSocketSharp.Server {
#region Internal Methods
internal void Bind(WebSocket socket, WebSocketServiceManager sessions)
internal void Bind(WebSocketContext context, WebSocketServiceManager sessions)
{
if (IsBound)
return;
_socket = socket;
_sessions = sessions;
_context = context;
_sessions = sessions;
_websocket = context.WebSocket;
_socket.OnOpen += onOpen;
_socket.OnMessage += onMessage;
_socket.OnError += onError;
_socket.OnClose += onClose;
_websocket.OnOpen += onOpen;
_websocket.OnMessage += onMessage;
_websocket.OnError += onError;
_websocket.OnClose += onClose;
IsBound = true;
}
internal void SendAsync(byte[] data, Action completed)
{
_socket.SendAsync(data, completed);
_websocket.SendAsync(data, completed);
}
internal void SendAsync(string data, Action completed)
{
_socket.SendAsync(data, completed);
_websocket.SendAsync(data, completed);
}
#endregion
@@ -288,7 +295,7 @@ namespace WebSocketSharp.Server {
public bool Ping(string message)
{
return IsBound
? _socket.Ping(message)
? _websocket.Ping(message)
: false;
}
@@ -340,7 +347,7 @@ namespace WebSocketSharp.Server {
public void Send(byte[] data)
{
if (IsBound)
_socket.Send(data);
_websocket.Send(data);
}
/// <summary>
@@ -352,7 +359,7 @@ namespace WebSocketSharp.Server {
public void Send(string data)
{
if (IsBound)
_socket.Send(data);
_websocket.Send(data);
}
/// <summary>
@@ -401,7 +408,7 @@ namespace WebSocketSharp.Server {
public void Start()
{
if (IsBound)
_socket.Connect();
_websocket.Connect();
}
/// <summary>
@@ -412,7 +419,7 @@ namespace WebSocketSharp.Server {
if (!IsBound)
return;
_socket.Close();
_websocket.Close();
}
/// <summary>
@@ -429,7 +436,7 @@ namespace WebSocketSharp.Server {
if (!IsBound)
return;
_socket.Close(code, reason);
_websocket.Close(code, reason);
}
/// <summary>

View File

@@ -229,15 +229,15 @@ namespace WebSocketSharp.Server {
#region Explicit Interface Implementation
/// <summary>
/// Binds the specified <see cref="WebSocket"/> to the WebSocket service instance.
/// Binds the specified <see cref="WebSocketContext"/> to a <see cref="WebSocketService"/> instance.
/// </summary>
/// <param name="socket">
/// A <see cref="WebSocket"/> to bind.
/// <param name="context">
/// A <see cref="WebSocketContext"/> that contains the WebSocket connection request objects to bind.
/// </param>
void IServiceHost.BindWebSocket(WebSocket socket)
void IServiceHost.BindWebSocket(WebSocketContext context)
{
T service = new T();
service.Bind(socket, _sessions);
service.Bind(context, _sessions);
service.Start();
}
@@ -246,25 +246,25 @@ namespace WebSocketSharp.Server {
#region Protected Method
/// <summary>
/// Accepts a WebSocket connection.
/// Accepts a WebSocket connection request.
/// </summary>
/// <param name="context">
/// A <see cref="TcpListenerWebSocketContext"/> that contains the WebSocket connection request objects.
/// </param>
protected override void AcceptWebSocket(TcpListenerWebSocketContext context)
{
var socket = context.WebSocket;
var path = context.Path.UrlDecode();
var websocket = context.WebSocket;
var path = context.Path.UrlDecode();
if (path != Uri.GetAbsolutePath().UrlDecode())
{
socket.Close(HttpStatusCode.NotImplemented);
websocket.Close(HttpStatusCode.NotImplemented);
return;
}
if (Uri.IsAbsoluteUri)
socket.Url = Uri;
websocket.Url = Uri;
((IServiceHost)this).BindWebSocket(socket);
((IServiceHost)this).BindWebSocket(context);
}
#endregion