diff --git a/Example/bin/Debug/example.exe b/Example/bin/Debug/example.exe index 3a91d762..39c97613 100755 Binary files a/Example/bin/Debug/example.exe and b/Example/bin/Debug/example.exe differ diff --git a/Example/bin/Debug/example.exe.mdb b/Example/bin/Debug/example.exe.mdb index f30bf839..2bb2881d 100644 Binary files a/Example/bin/Debug/example.exe.mdb and b/Example/bin/Debug/example.exe.mdb differ diff --git a/Example/bin/Debug/websocket-sharp.dll b/Example/bin/Debug/websocket-sharp.dll index 3950c3fe..aeda642a 100755 Binary files a/Example/bin/Debug/websocket-sharp.dll and b/Example/bin/Debug/websocket-sharp.dll differ diff --git a/Example/bin/Debug/websocket-sharp.dll.mdb b/Example/bin/Debug/websocket-sharp.dll.mdb index f3c03973..07b5cc4e 100644 Binary files a/Example/bin/Debug/websocket-sharp.dll.mdb and b/Example/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index 63febc5c..52790d8d 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/example.exe.mdb b/Example/bin/Debug_Ubuntu/example.exe.mdb index 3a9268e1..637dabb9 100644 Binary files a/Example/bin/Debug_Ubuntu/example.exe.mdb and b/Example/bin/Debug_Ubuntu/example.exe.mdb differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index b2c76b4d..823848b9 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 86949826..727ed67b 100644 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example/bin/Release/example.exe b/Example/bin/Release/example.exe index 19465893..4f431779 100755 Binary files a/Example/bin/Release/example.exe and b/Example/bin/Release/example.exe differ diff --git a/Example/bin/Release/websocket-sharp.dll b/Example/bin/Release/websocket-sharp.dll index d33d5220..238a1f07 100755 Binary files a/Example/bin/Release/websocket-sharp.dll and b/Example/bin/Release/websocket-sharp.dll differ diff --git a/Example/bin/Release_Ubuntu/example.exe b/Example/bin/Release_Ubuntu/example.exe index c732d6c1..584333aa 100755 Binary files a/Example/bin/Release_Ubuntu/example.exe and b/Example/bin/Release_Ubuntu/example.exe differ diff --git a/Example/bin/Release_Ubuntu/websocket-sharp.dll b/Example/bin/Release_Ubuntu/websocket-sharp.dll index 4160d674..06dd2af4 100755 Binary files a/Example/bin/Release_Ubuntu/websocket-sharp.dll and b/Example/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug/example1.exe b/Example1/bin/Debug/example1.exe index 6405f7b5..b671fe67 100755 Binary files a/Example1/bin/Debug/example1.exe and b/Example1/bin/Debug/example1.exe differ diff --git a/Example1/bin/Debug/example1.exe.mdb b/Example1/bin/Debug/example1.exe.mdb index f332a487..9b2d1986 100644 Binary files a/Example1/bin/Debug/example1.exe.mdb and b/Example1/bin/Debug/example1.exe.mdb differ diff --git a/Example1/bin/Debug/websocket-sharp.dll b/Example1/bin/Debug/websocket-sharp.dll index 3950c3fe..aeda642a 100755 Binary files a/Example1/bin/Debug/websocket-sharp.dll and b/Example1/bin/Debug/websocket-sharp.dll differ diff --git a/Example1/bin/Debug/websocket-sharp.dll.mdb b/Example1/bin/Debug/websocket-sharp.dll.mdb index f3c03973..07b5cc4e 100644 Binary files a/Example1/bin/Debug/websocket-sharp.dll.mdb and b/Example1/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index 3b7d93cc..d0245a21 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe.mdb b/Example1/bin/Debug_Ubuntu/example1.exe.mdb index 22c62b47..6896e170 100644 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe.mdb and b/Example1/bin/Debug_Ubuntu/example1.exe.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index b2c76b4d..823848b9 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 86949826..727ed67b 100644 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Release/example1.exe b/Example1/bin/Release/example1.exe index 8721bb86..5f91e410 100755 Binary files a/Example1/bin/Release/example1.exe and b/Example1/bin/Release/example1.exe differ diff --git a/Example1/bin/Release/websocket-sharp.dll b/Example1/bin/Release/websocket-sharp.dll index d33d5220..238a1f07 100755 Binary files a/Example1/bin/Release/websocket-sharp.dll and b/Example1/bin/Release/websocket-sharp.dll differ diff --git a/Example1/bin/Release_Ubuntu/example1.exe b/Example1/bin/Release_Ubuntu/example1.exe index d4dfc94e..aef4eb3f 100755 Binary files a/Example1/bin/Release_Ubuntu/example1.exe and b/Example1/bin/Release_Ubuntu/example1.exe differ diff --git a/Example1/bin/Release_Ubuntu/websocket-sharp.dll b/Example1/bin/Release_Ubuntu/websocket-sharp.dll index 4160d674..06dd2af4 100755 Binary files a/Example1/bin/Release_Ubuntu/websocket-sharp.dll and b/Example1/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug/example2.exe b/Example2/bin/Debug/example2.exe index eb52472d..f0c5304c 100755 Binary files a/Example2/bin/Debug/example2.exe and b/Example2/bin/Debug/example2.exe differ diff --git a/Example2/bin/Debug/example2.exe.mdb b/Example2/bin/Debug/example2.exe.mdb index ae882dc2..6ffbd10f 100644 Binary files a/Example2/bin/Debug/example2.exe.mdb and b/Example2/bin/Debug/example2.exe.mdb differ diff --git a/Example2/bin/Debug/websocket-sharp.dll b/Example2/bin/Debug/websocket-sharp.dll index 3950c3fe..aeda642a 100755 Binary files a/Example2/bin/Debug/websocket-sharp.dll and b/Example2/bin/Debug/websocket-sharp.dll differ diff --git a/Example2/bin/Debug/websocket-sharp.dll.mdb b/Example2/bin/Debug/websocket-sharp.dll.mdb index f3c03973..07b5cc4e 100644 Binary files a/Example2/bin/Debug/websocket-sharp.dll.mdb and b/Example2/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index a3a0fdd8..f58f496a 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe.mdb b/Example2/bin/Debug_Ubuntu/example2.exe.mdb index f707c081..972fa64e 100644 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe.mdb and b/Example2/bin/Debug_Ubuntu/example2.exe.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index b2c76b4d..823848b9 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 86949826..727ed67b 100644 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Release/example2.exe b/Example2/bin/Release/example2.exe index 063d17da..0ca1be63 100755 Binary files a/Example2/bin/Release/example2.exe and b/Example2/bin/Release/example2.exe differ diff --git a/Example2/bin/Release/websocket-sharp.dll b/Example2/bin/Release/websocket-sharp.dll index d33d5220..238a1f07 100755 Binary files a/Example2/bin/Release/websocket-sharp.dll and b/Example2/bin/Release/websocket-sharp.dll differ diff --git a/Example2/bin/Release_Ubuntu/example2.exe b/Example2/bin/Release_Ubuntu/example2.exe index 4ea4e2c1..61fc7660 100755 Binary files a/Example2/bin/Release_Ubuntu/example2.exe and b/Example2/bin/Release_Ubuntu/example2.exe differ diff --git a/Example2/bin/Release_Ubuntu/websocket-sharp.dll b/Example2/bin/Release_Ubuntu/websocket-sharp.dll index 4160d674..06dd2af4 100755 Binary files a/Example2/bin/Release_Ubuntu/websocket-sharp.dll and b/Example2/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/Example3.pidb b/Example3/Example3.pidb index 820e77cc..162891a4 100644 Binary files a/Example3/Example3.pidb and b/Example3/Example3.pidb differ diff --git a/Example3/Program.cs b/Example3/Program.cs index b93b1413..491dbecd 100644 --- a/Example3/Program.cs +++ b/Example3/Program.cs @@ -16,9 +16,9 @@ namespace Example3 { _httpsv = new HttpServer(4649); - _httpsv.OnResponse += (sender, e) => + _httpsv.OnGet += (sender, e) => { - onResponse(e.Context); + onGet(e.Request, e.Response); }; _httpsv.OnError += (sender, e) => @@ -54,19 +54,5 @@ namespace Example3 response.StatusCode = (int)HttpStatusCode.NotFound; } - - private static void onResponse(HttpListenerContext context) - { - var req = context.Request; - var res = context.Response; - - if (req.HttpMethod == "GET") - { - onGet(req, res); - return; - } - - res.StatusCode = (int)HttpStatusCode.MethodNotAllowed; - } } } diff --git a/Example3/bin/Debug/Example3.exe b/Example3/bin/Debug/Example3.exe index 66dca144..f4c2e510 100755 Binary files a/Example3/bin/Debug/Example3.exe and b/Example3/bin/Debug/Example3.exe differ diff --git a/Example3/bin/Debug/Example3.exe.mdb b/Example3/bin/Debug/Example3.exe.mdb index 6a5a0b11..29cb9a46 100644 Binary files a/Example3/bin/Debug/Example3.exe.mdb and b/Example3/bin/Debug/Example3.exe.mdb differ diff --git a/Example3/bin/Debug/websocket-sharp.dll b/Example3/bin/Debug/websocket-sharp.dll index 3950c3fe..aeda642a 100755 Binary files a/Example3/bin/Debug/websocket-sharp.dll and b/Example3/bin/Debug/websocket-sharp.dll differ diff --git a/Example3/bin/Debug/websocket-sharp.dll.mdb b/Example3/bin/Debug/websocket-sharp.dll.mdb index f3c03973..07b5cc4e 100644 Binary files a/Example3/bin/Debug/websocket-sharp.dll.mdb and b/Example3/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index 9e052a7c..ebe94ea0 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb index 958b095a..35d44e59 100644 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb and b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index b2c76b4d..823848b9 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 86949826..727ed67b 100644 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Release/Example3.exe b/Example3/bin/Release/Example3.exe index c21abd53..5bf7c26b 100755 Binary files a/Example3/bin/Release/Example3.exe and b/Example3/bin/Release/Example3.exe differ diff --git a/Example3/bin/Release/websocket-sharp.dll b/Example3/bin/Release/websocket-sharp.dll index d33d5220..238a1f07 100755 Binary files a/Example3/bin/Release/websocket-sharp.dll and b/Example3/bin/Release/websocket-sharp.dll differ diff --git a/Example3/bin/Release_Ubuntu/Example3.exe b/Example3/bin/Release_Ubuntu/Example3.exe index cbafb085..f3e6951a 100755 Binary files a/Example3/bin/Release_Ubuntu/Example3.exe and b/Example3/bin/Release_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Release_Ubuntu/websocket-sharp.dll b/Example3/bin/Release_Ubuntu/websocket-sharp.dll index 4160d674..06dd2af4 100755 Binary files a/Example3/bin/Release_Ubuntu/websocket-sharp.dll and b/Example3/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 4f50ef7d..39efab79 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -67,6 +67,7 @@ namespace WebSocketSharp { if (value < 0) throw new ArgumentOutOfRangeException("value"); + byte b = (byte)value; dest.Add(b); return b == Convert.ToByte(c); diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index 1d834801..4de1eac4 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -67,9 +67,9 @@ namespace WebSocketSharp.Server { var prefix = String.Format( "http{0}://*:{1}/", _port == 443 ? "s" : String.Empty, _port); _listener.Prefixes.Add(prefix); - _rootPath = ConfigurationManager.AppSettings["RootPath"]; _wsPath = wsPath.ToUri(); _wsServer = new WebSocketServer(); + configureFromConfigFile(); } #endregion @@ -84,8 +84,16 @@ namespace WebSocketSharp.Server { #region Events + public event EventHandler OnConnect; + public event EventHandler OnDelete; public event EventHandler OnError; - public event EventHandler OnResponse; + public event EventHandler OnGet; + public event EventHandler OnHead; + public event EventHandler OnOptions; + public event EventHandler OnPatch; + public event EventHandler OnPost; + public event EventHandler OnPut; + public event EventHandler OnTrace; #endregion @@ -113,23 +121,25 @@ namespace WebSocketSharp.Server { } } + private void configureFromConfigFile() + { + _rootPath = ConfigurationManager.AppSettings["RootPath"]; + } + private void respond(HttpListenerContext context) { WaitCallback respondCb = (state) => { try { - var req = context.Request; - var res = context.Response; - - if (req.IsWebSocketRequest) + if (context.Request.IsWebSocketRequest) { upgradeToWebSocket(context); } else { - OnResponse.Emit(this, new ResponseEventArgs(context)); - res.Close(); + respondToClient(context); + context.Response.Close(); } } catch (Exception ex) @@ -140,6 +150,69 @@ namespace WebSocketSharp.Server { ThreadPool.QueueUserWorkItem(respondCb); } + private void respondToClient(HttpListenerContext context) + { + var req = context.Request; + var res = context.Response; + var eventArgs = new ResponseEventArgs(context); + + if (req.HttpMethod == "GET" && OnGet != null) + { + OnGet(this, eventArgs); + return; + } + + if (req.HttpMethod == "HEAD" && OnHead != null) + { + OnHead(this, eventArgs); + return; + } + + if (req.HttpMethod == "POST" && OnPost != null) + { + OnPost(this, eventArgs); + return; + } + + if (req.HttpMethod == "PUT" && OnPut != null) + { + OnPut(this, eventArgs); + return; + } + + if (req.HttpMethod == "DELETE" && OnDelete != null) + { + OnDelete(this, eventArgs); + return; + } + + if (req.HttpMethod == "OPTIONS" && OnOptions != null) + { + OnOptions(this, eventArgs); + return; + } + + if (req.HttpMethod == "TRACE" && OnTrace != null) + { + OnTrace(this, eventArgs); + return; + } + + if (req.HttpMethod == "CONNECT" && OnConnect != null) + { + OnConnect(this, eventArgs); + return; + } + + if (req.HttpMethod == "PATCH" && OnPatch != null) + { + OnPatch(this, eventArgs); + return; + } + + res.StatusCode = (int)HttpStatusCode.NotImplemented; + } + private void startAcceptRequestThread() { _acceptRequestThread = new Thread(new ThreadStart(acceptRequest)); diff --git a/websocket-sharp/Server/ResponseEventArgs.cs b/websocket-sharp/Server/ResponseEventArgs.cs index 2dbe7fa1..81a651b4 100644 --- a/websocket-sharp/Server/ResponseEventArgs.cs +++ b/websocket-sharp/Server/ResponseEventArgs.cs @@ -33,11 +33,13 @@ namespace WebSocketSharp.Server { public class ResponseEventArgs : EventArgs { - public HttpListenerContext Context { get; private set; } + public HttpListenerRequest Request { get; private set; } + public HttpListenerResponse Response { get; private set; } public ResponseEventArgs(HttpListenerContext context) { - Context = context; + Request = context.Request; + Response = context.Response; } } } diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 8e581edf..3d1bba36 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -677,9 +677,9 @@ namespace WebSocketSharp { close(CloseStatusCode.TOO_BIG, ex.Message); } - catch (Exception ex) + catch (Exception) { - close(CloseStatusCode.ABNORMAL, ex.Message); + close(CloseStatusCode.ABNORMAL, "An exception has been raised."); } } @@ -1075,7 +1075,7 @@ namespace WebSocketSharp catch (Exception ex) { error(ex.Message); - close(CloseStatusCode.HANDSHAKE_FAILURE, ex.Message); + close(CloseStatusCode.HANDSHAKE_FAILURE, "An exception has been raised."); } } diff --git a/websocket-sharp/WsReceivedTooBigMessageException.cs b/websocket-sharp/WsReceivedTooBigMessageException.cs index bf50e89e..057707f2 100644 --- a/websocket-sharp/WsReceivedTooBigMessageException.cs +++ b/websocket-sharp/WsReceivedTooBigMessageException.cs @@ -38,7 +38,7 @@ namespace WebSocketSharp static WsReceivedTooBigMessageException() { _defaultMessage = String.Format( - "Client received a payload data bigger than the allowable value({0} bytes).", PayloadData.MaxLength); + "Size of received payload data is bigger than the allowable value({0} bytes).", PayloadData.MaxLength); } public WsReceivedTooBigMessageException() diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index 3950c3fe..aeda642a 100755 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll and b/websocket-sharp/bin/Debug/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb index f3c03973..07b5cc4e 100644 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index b2c76b4d..823848b9 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 86949826..727ed67b 100644 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Release/websocket-sharp.dll b/websocket-sharp/bin/Release/websocket-sharp.dll index d33d5220..238a1f07 100755 Binary files a/websocket-sharp/bin/Release/websocket-sharp.dll and b/websocket-sharp/bin/Release/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll index 4160d674..06dd2af4 100755 Binary files a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index 22781a1e..9dca2fc0 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ