Fix due to the added IsValidWsUri method to Ext.cs

This commit is contained in:
sta
2012-09-25 10:48:33 +09:00
parent 14f16577be
commit a75903c488
25 changed files with 62 additions and 56 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -4
View File
@@ -7,7 +7,7 @@ namespace Example2
{
public static void Main(string[] args)
{
/* Single service server
// Single service server
var wssv = new WebSocketServer<Echo>("ws://localhost:4649");
//var wssv = new WebSocketServer<Echo>(4649);
//var wssv = new WebSocketServer<Chat>("ws://localhost:4649");
@@ -17,9 +17,9 @@ namespace Example2
Console.WriteLine(
"WebSocket Server (url: {0})\n listening on address: {1} port: {2}\n",
wssv.Uri, wssv.Address, wssv.Port);
*/
// Multi services server
/* Multi services server
var wssv = new WebSocketServer(4649);
wssv.AddService<Echo>("/Echo");
wssv.AddService<Chat>("/Chat");
@@ -27,7 +27,7 @@ namespace Example2
wssv.Start();
Console.WriteLine(
"WebSocket Server listening on port: {0}\n", wssv.Port);
*/
Console.WriteLine("Press any key to stop server...");
Console.ReadLine();
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+42 -1
View File
@@ -37,6 +37,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using WebSocketSharp.Net;
@@ -166,6 +167,45 @@ namespace WebSocketSharp
return false;
}
public static bool IsValidWsUri(this Uri uri, out string message)
{
if (!uri.IsAbsoluteUri)
{
message = "Not absolute uri: " + uri.ToString();
return false;
}
var scheme = uri.Scheme;
if (scheme != "ws" && scheme != "wss")
{
message = "Unsupported WebSocket URI scheme: " + scheme;
return false;
}
var port = uri.Port;
if (port > 0)
{
if ((scheme == "wss" && port != 443) ||
(scheme != "wss" && port == 443))
{
message = String.Format(
"Invalid pair of WebSocket URI scheme and port: {0}, {1}", scheme, port);
return false;
}
}
var host = uri.DnsSafeHost;
var addrs = Dns.GetHostAddresses(host);
if (addrs.Length == 0)
{
message = "Invalid WebSocket URI host: " + host;
return false;
}
message = String.Empty;
return true;
}
// Derived from System.Uri.MaybeUri method
public static bool MaybeUri(this string uriString)
{
@@ -414,7 +454,8 @@ namespace WebSocketSharp
return new Uri(uriString);
}
public static void WriteContent(this HttpListenerResponse response, byte[] content)
public static void WriteContent(
this WebSocketSharp.Net.HttpListenerResponse response, byte[] content)
{
var output = response.OutputStream;
response.ContentLength64 = content.Length;
+11 -36
View File
@@ -55,17 +55,14 @@ namespace WebSocketSharp.Server {
protected WebSocketServerBase(string url)
{
string msg;
if (!isValidUri(url, out msg))
throw new ArgumentException(msg, "url");
init();
init(url);
}
protected WebSocketServerBase(IPAddress address, int port)
{
_port = port <= 0 ? 80 : port;
_address = address;
_port = port <= 0 ? 80 : port;
init();
}
@@ -149,48 +146,26 @@ namespace WebSocketSharp.Server {
_isSelfHost = true;
}
private bool isValidUri(string url, out string message)
private void init(string url)
{
var uri = url.ToUri();
if (!uri.IsAbsoluteUri)
{
message = "Not absolute uri: " + url;
return false;
}
string msg;
if (!uri.IsValidWsUri(out msg))
throw new ArgumentException(msg, "url");
var scheme = uri.Scheme;
var port = uri.Port;
var host = uri.DnsSafeHost;
var ips = Dns.GetHostAddresses(host);
if (scheme != "ws" && scheme != "wss")
{
message = "Unsupported WebSocket URI scheme: " + scheme;
return false;
}
if ((scheme == "wss" && port != 443) ||
(scheme != "wss" && port == 443))
{
message = String.Format(
"Invalid pair of WebSocket URI scheme and port: {0}, {1}", scheme, port);
return false;
}
if (ips.Length == 0)
{
message = "Invalid WebSocket URI host: " + host;
return false;
}
var addrs = Dns.GetHostAddresses(host);
if (port <= 0)
port = scheme == "ws" ? 80 : 443;
_address = ips[0];
_address = addrs[0];
_port = port;
message = String.Empty;
return true;
init();
}
private void startAcceptClientThread()
+5 -15
View File
@@ -142,17 +142,16 @@ namespace WebSocketSharp
public WebSocket(string url, params string[] protocols)
: this()
{
var uri = new Uri(url);
if (!isValidScheme(uri))
{
var msg = "Unsupported WebSocket URI scheme: " + uri.Scheme;
var uri = url.ToUri();
string msg;
if (!uri.IsValidWsUri(out msg))
throw new ArgumentException(msg, "url");
}
_uri = uri;
_protocols = protocols.ToString(", ");
_isClient = true;
_isSecure = _uri.Scheme == "wss" ? true : false;
_isSecure = uri.Scheme == "wss" ? true : false;
}
public WebSocket(
@@ -597,15 +596,6 @@ namespace WebSocketSharp
return true;
}
private bool isValidScheme(Uri uri)
{
string scheme = uri.Scheme;
if (scheme == "ws" || scheme == "wss")
return true;
return false;
}
private void message()
{
try
Binary file not shown.
Binary file not shown.