Fix due to the modified WebSocket.cs

This commit is contained in:
sta 2012-10-13 17:38:19 +09:00
parent 97ecfc5d2b
commit 33cddb9fa2
24 changed files with 68 additions and 47 deletions

Binary file not shown.

Binary file not shown.

View File

@ -101,8 +101,7 @@ ws.OnClose += (sender, e) =>
}; };
``` ```
The `e.Code` (`WebSocketSharp.CloseEventArgs.Code`, its type is `WebSocketSharp.Frame.CloseStatusCode`) contains the close status code The `e.Code` (`WebSocketSharp.CloseEventArgs.Code`, its type is `WebSocketSharp.Frame.CloseStatusCode`) contains the close status code and the `e.Reason` (`WebSocketSharp.CloseEventArgs.Reason`, its type is `string`) contains the reason why closes, so you operate them.
and the `e.Reason` (`WebSocketSharp.CloseEventArgs.Reason`, its type is `string`) contains the reason why closes, so you operate them.
#### Step 4 #### #### Step 4 ####

View File

@ -228,11 +228,11 @@ namespace WebSocketSharp {
return false; return false;
} }
public static bool IsValidWsUri(this Uri uri, out string message) public static bool IsValidWebSocketUri(this Uri uri, out string message)
{ {
if (!uri.IsAbsoluteUri) if (!uri.IsAbsoluteUri)
{ {
message = "Not absolute uri: " + uri.ToString(); message = "Not absolute URI: " + uri.ToString();
return false; return false;
} }
@ -243,11 +243,18 @@ namespace WebSocketSharp {
return false; return false;
} }
var original = uri.OriginalString;
if (original.Contains('#'))
{
message = "WebSocket URI must not contain the fragment identifier: " + original;
return false;
}
var port = uri.Port; var port = uri.Port;
if (port > 0) if (port > 0)
{ {
if ((scheme == "wss" && port != 443) || if ((scheme == "ws" && port == 443) ||
(scheme != "wss" && port == 443)) (scheme == "wss" && port == 80))
{ {
message = String.Format( message = String.Format(
"Invalid pair of WebSocket URI scheme and port: {0}, {1}", scheme, port); "Invalid pair of WebSocket URI scheme and port: {0}, {1}", scheme, port);
@ -255,14 +262,6 @@ namespace WebSocketSharp {
} }
} }
var host = uri.DnsSafeHost;
var addrs = System.Net.Dns.GetHostAddresses(host);
if (addrs.Length == 0)
{
message = "Invalid WebSocket URI host: " + host;
return false;
}
message = String.Empty; message = String.Empty;
return true; return true;
} }

View File

@ -151,7 +151,7 @@ namespace WebSocketSharp.Server {
var uri = url.ToUri(); var uri = url.ToUri();
string msg; string msg;
if (!uri.IsValidWsUri(out msg)) if (!uri.IsValidWebSocketUri(out msg))
throw new ArgumentException(msg, "url"); throw new ArgumentException(msg, "url");
var scheme = uri.Scheme; var scheme = uri.Scheme;

View File

@ -49,8 +49,7 @@ namespace WebSocketSharp {
/// Implements the WebSocket interface. /// Implements the WebSocket interface.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The WebSocket class provides methods and properties for two-way communication with a remote host /// The WebSocket class provides methods and properties for two-way communication using the WebSocket protocol (RFC 6455).
/// with the WebSocket protocol (RFC 6455).
/// </remarks> /// </remarks>
public class WebSocket : IDisposable public class WebSocket : IDisposable
{ {
@ -143,52 +142,58 @@ namespace WebSocketSharp {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WebSocketSharp.WebSocket"/> class with the specified WebSocket URL and subprotocols. /// Initializes a new instance of the <see cref="WebSocketSharp.WebSocket"/> class with the specified WebSocket URL and subprotocols.
/// </summary> /// </summary>
/// <param name='url'> /// <param name="url">
/// A <see cref="string"/> that contains the WebSocket URL. /// A <see cref="string"/> that contains the WebSocket URL.
/// </param> /// </param>
/// <param name='protocols'> /// <param name="protocols">
/// An array of <see cref="string"/> that contains the WebSocket subprotocols if any. /// An array of <see cref="string"/> that contains the WebSocket subprotocols if any.
/// </param> /// </param>
/// <exception cref='ArgumentException'> /// <exception cref="ArgumentNullException">
/// <paramref name="url"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="url"/> is not valid WebSocket URL. /// <paramref name="url"/> is not valid WebSocket URL.
/// </exception> /// </exception>
public WebSocket(string url, params string[] protocols) public WebSocket(string url, params string[] protocols)
: this() : this()
{ {
var uri = url.ToUri(); if (url == null)
throw new ArgumentNullException("url");
string msg; string msg;
if (!uri.IsValidWsUri(out msg)) if (!isValidUrl(url, out msg))
throw new ArgumentException(msg, "url"); throw new ArgumentException(msg, "url");
_uri = uri;
_protocols = protocols.ToString(", "); _protocols = protocols.ToString(", ");
_isClient = true; _isClient = true;
_isSecure = uri.Scheme == "wss" ? true : false; _isSecure = _uri.Scheme == "wss" ? true : false;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WebSocketSharp.WebSocket"/> class with the specified WebSocket URL, OnOpen, OnMessage, OnError, OnClose event handlers and subprotocols. /// Initializes a new instance of the <see cref="WebSocketSharp.WebSocket"/> class with the specified WebSocket URL, OnOpen, OnMessage, OnError, OnClose event handlers and subprotocols.
/// </summary> /// </summary>
/// <param name='url'> /// <param name="url">
/// A <see cref="string"/> that contains the WebSocket URL. /// A <see cref="string"/> that contains the WebSocket URL.
/// </param> /// </param>
/// <param name='onOpen'> /// <param name="onOpen">
/// An OnOpen event handler. /// An OnOpen event handler.
/// </param> /// </param>
/// <param name='onMessage'> /// <param name="onMessage">
/// An OnMessage event handler. /// An OnMessage event handler.
/// </param> /// </param>
/// <param name='onError'> /// <param name="onError">
/// An OnError event handler. /// An OnError event handler.
/// </param> /// </param>
/// <param name='onClose'> /// <param name="onClose">
/// An OnClose event handler. /// An OnClose event handler.
/// </param> /// </param>
/// <param name='protocols'> /// <param name="protocols">
/// An array of <see cref="string"/> that contains the WebSocket subprotocols if any. /// An array of <see cref="string"/> that contains the WebSocket subprotocols if any.
/// </param> /// </param>
/// <exception cref='ArgumentException'> /// <exception cref="ArgumentNullException">
/// <paramref name="url"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="url"/> is not valid WebSocket URL. /// <paramref name="url"/> is not valid WebSocket URL.
/// </exception> /// </exception>
public WebSocket( public WebSocket(
@ -687,6 +692,24 @@ namespace WebSocketSharp {
return true; return true;
} }
private bool isValidUrl(string url, out string message)
{
if (url == String.Empty)
{
message = "'url' is empty.";
return false;
}
var uri = url.ToUri();
if (!uri.IsValidWebSocketUri(out message))
return false;
_uri = uri;
message = String.Empty;
return true;
}
private void message() private void message()
{ {
try try
@ -1082,7 +1105,7 @@ namespace WebSocketSharp {
#region Public Methods #region Public Methods
/// <summary> /// <summary>
/// Sends a Close frame and closes the WebSocket connection and releases all associated resources. /// Sends a Close frame using the connection and closes the connection and releases all associated resources.
/// </summary> /// </summary>
public void Close() public void Close()
{ {
@ -1090,9 +1113,9 @@ namespace WebSocketSharp {
} }
/// <summary> /// <summary>
/// Sends a Close frame and closes the WebSocket connection and releases all associated resources. /// Sends a Close frame using the connection and closes the connection and releases all associated resources.
/// </summary> /// </summary>
/// <param name='code'> /// <param name="code">
/// A <see cref="WebSocketSharp.Frame.CloseStatusCode"/>. /// A <see cref="WebSocketSharp.Frame.CloseStatusCode"/>.
/// </param> /// </param>
public void Close(CloseStatusCode code) public void Close(CloseStatusCode code)
@ -1101,12 +1124,12 @@ namespace WebSocketSharp {
} }
/// <summary> /// <summary>
/// Sends a Close frame and closes the WebSocket connection and releases all associated resources. /// Sends a Close frame using the connection and closes the connection and releases all associated resources.
/// </summary> /// </summary>
/// <param name='code'> /// <param name="code">
/// A <see cref="WebSocketSharp.Frame.CloseStatusCode"/>. /// A <see cref="WebSocketSharp.Frame.CloseStatusCode"/>.
/// </param> /// </param>
/// <param name='reason'> /// <param name="reason">
/// A <see cref="string"/> that contains the reason why closes. /// A <see cref="string"/> that contains the reason why closes.
/// </param> /// </param>
public void Close(CloseStatusCode code, string reason) public void Close(CloseStatusCode code, string reason)
@ -1146,7 +1169,7 @@ namespace WebSocketSharp {
} }
/// <summary> /// <summary>
/// Sends a Close frame and closes the WebSocket connection and releases all associated resources. /// Sends a Close frame using the connection and closes the connection and releases all associated resources.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Call <see cref="Dispose"/> when you are finished using the <see cref="WebSocketSharp.WebSocket"/>. The /// Call <see cref="Dispose"/> when you are finished using the <see cref="WebSocketSharp.WebSocket"/>. The
@ -1160,7 +1183,7 @@ namespace WebSocketSharp {
} }
/// <summary> /// <summary>
/// Sends a Ping frame. /// Sends a Ping frame using the connection.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// <c>true</c> if the WebSocket receives a Pong frame in a time; otherwise, <c>false</c>. /// <c>true</c> if the WebSocket receives a Pong frame in a time; otherwise, <c>false</c>.
@ -1171,9 +1194,9 @@ namespace WebSocketSharp {
} }
/// <summary> /// <summary>
/// Sends a Ping frame with a message. /// Sends a Ping frame with a message using the connection.
/// </summary> /// </summary>
/// <param name='data'> /// <param name="data">
/// A <see cref="string"/> that contains the message data to be sent. /// A <see cref="string"/> that contains the message data to be sent.
/// </param> /// </param>
/// <returns> /// <returns>
@ -1185,9 +1208,9 @@ namespace WebSocketSharp {
} }
/// <summary> /// <summary>
/// Sends a Text data frame. /// Sends a text data using the connection.
/// </summary> /// </summary>
/// <param name='data'> /// <param name="data">
/// A <see cref="string"/> that contains the text data to be sent. /// A <see cref="string"/> that contains the text data to be sent.
/// </param> /// </param>
public void Send(string data) public void Send(string data)
@ -1197,9 +1220,9 @@ namespace WebSocketSharp {
} }
/// <summary> /// <summary>
/// Sends a Binary data frame. /// Sends a binary data using the connection.
/// </summary> /// </summary>
/// <param name='data'> /// <param name="data">
/// An array of <see cref="byte"/> that contains the binary data to be sent. /// An array of <see cref="byte"/> that contains the binary data to be sent.
/// </param> /// </param>
public void Send(byte[] data) public void Send(byte[] data)
@ -1208,9 +1231,9 @@ namespace WebSocketSharp {
} }
/// <summary> /// <summary>
/// Sends a Binary data frame. /// Sends a binary data using the connection.
/// </summary> /// </summary>
/// <param name='file'> /// <param name="file">
/// A <see cref="FileInfo"/> that contains the binary data to be sent. /// A <see cref="FileInfo"/> that contains the binary data to be sent.
/// </param> /// </param>
public void Send(FileInfo file) public void Send(FileInfo file)

Binary file not shown.