diff --git a/Example/Example.pidb b/Example/Example.pidb
index e8af61bf..422aa8bd 100644
Binary files a/Example/Example.pidb and b/Example/Example.pidb differ
diff --git a/Example/bin/Debug/example.exe b/Example/bin/Debug/example.exe
index 3c76bb23..998657f7 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 80eaa185..0b001a9f 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 a3c86269..20929dc0 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 83a06f05..8539c648 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 31b552f0..f1d7dec8 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 8fb49fe8..9f560502 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 e318f2b9..922e8243 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 8e296ffa..62ee767a 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 2612eac0..6fb201d8 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 c41cbdc8..edcbe95f 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 cdbf41c8..50d4e151 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 9541e270..8637619b 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/AudioStreamer.cs b/Example1/AudioStreamer.cs
index 3a0a6cc7..110a23a9 100644
--- a/Example1/AudioStreamer.cs
+++ b/Example1/AudioStreamer.cs
@@ -12,7 +12,7 @@ using System.Threading;
using WebSocketSharp;
using WebSocketSharp.Frame;
-namespace Example
+namespace Example1
{
public struct NfMessage
{
diff --git a/Example1/Example1.pidb b/Example1/Example1.pidb
index 02ab1ea4..6a620199 100644
Binary files a/Example1/Example1.pidb and b/Example1/Example1.pidb differ
diff --git a/Example1/Program.cs b/Example1/Program.cs
index 2e33eee3..95218014 100644
--- a/Example1/Program.cs
+++ b/Example1/Program.cs
@@ -1,7 +1,7 @@
using System;
using System.Threading;
-namespace Example
+namespace Example1
{
public class Program
{
diff --git a/Example1/bin/Debug/example1.exe b/Example1/bin/Debug/example1.exe
index 2cfd924f..05a523c4 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 87d20e00..37b85bf6 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 a3c86269..20929dc0 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 83a06f05..8539c648 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 747660a6..4d35950e 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 55757034..f5c8b68d 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 e318f2b9..922e8243 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 8e296ffa..62ee767a 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 cefdb422..59917bf6 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 c41cbdc8..edcbe95f 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 70d334fa..a5e2e2ff 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 9541e270..8637619b 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/Chat.cs b/Example2/Chat.cs
new file mode 100644
index 00000000..c13b37f8
--- /dev/null
+++ b/Example2/Chat.cs
@@ -0,0 +1,14 @@
+using System;
+using WebSocketSharp;
+using WebSocketSharp.Server;
+
+namespace Example2
+{
+ public class Chat : WebSocketService
+ {
+ protected override void onMessage(object sender, MessageEventArgs e)
+ {
+ Server.Send(e.Data);
+ }
+ }
+}
diff --git a/Example2/Echo.cs b/Example2/Echo.cs
new file mode 100644
index 00000000..a75962f8
--- /dev/null
+++ b/Example2/Echo.cs
@@ -0,0 +1,14 @@
+using System;
+using WebSocketSharp;
+using WebSocketSharp.Server;
+
+namespace Example2
+{
+ public class Echo : WebSocketService
+ {
+ protected override void onMessage(object sender, MessageEventArgs e)
+ {
+ Send(e.Data);
+ }
+ }
+}
diff --git a/Example2/Example2.csproj b/Example2/Example2.csproj
index aee5e9bf..65bdb259 100644
--- a/Example2/Example2.csproj
+++ b/Example2/Example2.csproj
@@ -53,6 +53,8 @@
+
+
diff --git a/Example2/Example2.pidb b/Example2/Example2.pidb
index 9dd560e7..df6f1c68 100644
Binary files a/Example2/Example2.pidb and b/Example2/Example2.pidb differ
diff --git a/Example2/Program.cs b/Example2/Program.cs
index 9a59dcc4..d55d03d0 100644
--- a/Example2/Program.cs
+++ b/Example2/Program.cs
@@ -1,27 +1,15 @@
using System;
using System.Threading;
-using WebSocketSharp;
+using WebSocketSharp.Server;
-namespace Example
+namespace Example2
{
public class Program
{
- public static void Main (string[] args)
+ public static void Main(string[] args)
{
- //WebSocketServer wssv = new WebSocketServer("ws://localhost");
- WebSocketServer wssv = new WebSocketServer("ws://localhost:4649");
-
- wssv.OnConnection += (sender, e) =>
- {
- WebSocket ws = e.Socket;
- ws.OnMessage += (sender_, e_) =>
- {
- // Echo
- ws.Send(e_.Data);
- // Chat
- //wssv.Send(e_.Data);
- };
- };
+ var wssv = new WebSocketServer("ws://localhost:4649");
+ //var wssv = new WebSocketServer("ws://localhost:4649");
wssv.Start();
Console.WriteLine(
diff --git a/Example2/bin/Debug/example2.exe b/Example2/bin/Debug/example2.exe
index ff910fb1..6dd6c1ac 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 657a1457..e0bd0c04 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 a3c86269..20929dc0 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 83a06f05..8539c648 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 53a99ad6..0a454920 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 f535430b..ffb2f075 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 e318f2b9..922e8243 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 8e296ffa..62ee767a 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 9c802bce..ee98fca3 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 c41cbdc8..edcbe95f 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 febb55f2..ffac0df2 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 9541e270..8637619b 100755
Binary files a/Example2/bin/Release_Ubuntu/websocket-sharp.dll and b/Example2/bin/Release_Ubuntu/websocket-sharp.dll differ
diff --git a/README.md b/README.md
index e8829d48..45cf842b 100644
--- a/README.md
+++ b/README.md
@@ -124,56 +124,56 @@ Type of `code` is `WebSocketSharp.Frame.CloseStatusCode`, type of `reason` is `s
Required namespaces.
- using WebSocketSharp;
- using WebSocketSharp.Frame;
+ using WebSocketSharp.Server;
-Same as **WebSocket Client**.
+`WebSocketServer` class exists in `WebSocketSharp.Server` namespace.
#### Step 2 ####
-Creating instance of `WebSocketServer` class.
+Creating a class that inherits from `WebSocketService`.
- WebSocketServer wssv = new WebSocketServer("ws://example.com:4649");
+For example, if you want to provide the echo service,
-If you set WebSocket url without port number, `WebSocketServer` set 80 or 443 to port number automatically.
+ using WebSocketSharp;
+ using WebSocketSharp.Server;
+
+ public class Echo : WebSocketService
+ {
+ protected override void onMessage(object sender, MessageEventArgs e)
+ {
+ Send(e.Data);
+ }
+ }
+
+For example, if you want to provide the chat service,
+
+ using WebSocketSharp;
+ using WebSocketSharp.Server;
+
+ public class Chat : WebSocketService
+ {
+ protected override void onMessage(object sender, MessageEventArgs e)
+ {
+ Server.Send(e.Data);
+ }
+ }
+
+#### Step 3 ####
+
+Creating instance of `WebSocketServer` class.
+
+ var wssv = new WebSocketServer("ws://example.com:4649");
+
+Type of `T` inherits from `WebSocketService` class, so you can use a class that was created in **Step 2**.
+
+If you set WebSocket url without port number, `WebSocketServer` set 80 or 443 to port number automatically.
So it is necessary to run with root permission.
$ sudo mono example2.exe
-#### Step 3 ####
+#### Step 4 ####
-Setting WebSocketServer event handlers.
-
-##### WebSocketServer.OnConnection event #####
-
-`WebSocketServer.OnConnection` event is emitted each time client makes a connection request.
-
- wssv.OnConnection += (sender, e) =>
- {
- ...
- };
-
-`WebSocket` to communicate with client is stored in `e.Socket` (`WebSocketSharp.ConnectionEventArgs.Socket`, its type is `WebSocketSharp.WebSocket`), so you operate it.
-
- WebSocket ws = e.Socket;
- ws.OnMessage += (sender_, e_) =>
- {
- ...
- };
-
-Same settings of `WebSocket` event handlers as **WebSocket Client**.
-
-This WebSocket is server-side, so data is sent from server to client.
-
-If you want to function as echo server that returns a data to client as it is received,
-
- // Echo
- ws.Send(e_.Data);
-
-If you want to function as chat server that returns a data to all clients,
-
- // Chat
- wssv.Send(e_.Data);
+Setting WebSocketServer event handler.
##### WebSocketServer.OnError event #####
@@ -186,22 +186,12 @@ If you want to function as chat server that returns a data to all clients,
Error message is stored in `e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, its type is `string`), so you operate it.
-#### Step 4 ####
+#### Step 5 ####
Starting server.
wssv.Start();
-#### Step 5 ####
-
-Sending data to all clients.
-
- wssv.Send(data);
-
-`WebSocketServer.Send` method is overloaded.
-
-`data` types are `string` and `byte[]`.
-
#### Step 6 ####
Stopping server.
diff --git a/websocket-sharp.userprefs b/websocket-sharp.userprefs
index 8d2074ef..8a063dbf 100644
--- a/websocket-sharp.userprefs
+++ b/websocket-sharp.userprefs
@@ -1,10 +1,6 @@
-
-
-
-
-
+
diff --git a/websocket-sharp/ConnectionEventArgs.cs b/websocket-sharp/Server/IWebSocketServer.cs
similarity index 74%
rename from websocket-sharp/ConnectionEventArgs.cs
rename to websocket-sharp/Server/IWebSocketServer.cs
index 9b2c3615..f8766096 100644
--- a/websocket-sharp/ConnectionEventArgs.cs
+++ b/websocket-sharp/Server/IWebSocketServer.cs
@@ -1,6 +1,6 @@
#region MIT License
/**
- * ConnectionEventArgs.cs
+ * IWebSocketServer.cs
*
* The MIT License
*
@@ -27,16 +27,20 @@
#endregion
using System;
+using WebSocketSharp.Frame;
-namespace WebSocketSharp
+namespace WebSocketSharp.Server
{
- public class ConnectionEventArgs : EventArgs
+ public interface IWebSocketServer
{
- public WebSocket Socket { get; private set; }
-
- public ConnectionEventArgs(WebSocket webSocket)
- {
- Socket = webSocket;
- }
+ void AddService(WebSocketService service);
+ void Close();
+ void Close(CloseStatusCode code, string reason);
+ void Ping(string data);
+ void RemoveService(WebSocketService service);
+ void Send(byte[] data);
+ void Send(string data);
+ void Start();
+ void Stop();
}
}
diff --git a/websocket-sharp/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs
similarity index 74%
rename from websocket-sharp/WebSocketServer.cs
rename to websocket-sharp/Server/WebSocketServer.cs
index 1d1677e5..468696f4 100644
--- a/websocket-sharp/WebSocketServer.cs
+++ b/websocket-sharp/Server/WebSocketServer.cs
@@ -37,15 +37,16 @@ using System.Text;
using System.Threading;
using WebSocketSharp.Frame;
-namespace WebSocketSharp
+namespace WebSocketSharp.Server
{
- public class WebSocketServer
+ public class WebSocketServer : IWebSocketServer
+ where T : WebSocketService, new()
{
#region Private Fields
- private TcpListener _tcpListener;
- private Uri _uri;
- private SynchronizedCollection _webSockets;
+ private SynchronizedCollection _services;
+ private TcpListener _tcpListener;
+ private Uri _uri;
#endregion
@@ -75,8 +76,7 @@ namespace WebSocketSharp
#region Events
- public event EventHandler OnConnection;
- public event EventHandler OnError;
+ public event EventHandler OnError;
#endregion
@@ -106,7 +106,7 @@ namespace WebSocketSharp
}
_tcpListener = new TcpListener(IPAddress.Any, port);
- _webSockets = new SynchronizedCollection();
+ _services = new SynchronizedCollection();
}
#endregion
@@ -125,12 +125,10 @@ namespace WebSocketSharp
try
{
TcpClient client = listener.EndAcceptTcpClient(ar);
-
- WebSocket ws = new WebSocket(_uri.ToString(), client);
- OnConnection.Emit(this, new ConnectionEventArgs(ws));
- _webSockets.Add(ws);
-
- ws.Connect();
+ WebSocket socket = new WebSocket(_uri.ToString(), client);
+ T service = new T();
+ service.Bind(this, socket);
+ service.Open();
}
catch (ObjectDisposedException)
{
@@ -170,32 +168,56 @@ namespace WebSocketSharp
#region Public Methods
+ public void AddService(WebSocketService service)
+ {
+ _services.Add(service);
+ }
+
+ public void Close()
+ {
+ Close(CloseStatusCode.NORMAL, String.Empty);
+ }
+
public void Close(CloseStatusCode code, string reason)
{
- lock (_webSockets.SyncRoot)
+ lock (_services.SyncRoot)
{
- foreach (WebSocket ws in _webSockets)
+ foreach (WebSocketService service in _services)
{
- if (ws.ReadyState == WsState.OPEN)
- {
- ws.Close(code, reason);
- }
+ service.Close(code, reason);
}
}
}
+ public void Ping(string data)
+ {
+ WaitCallback broadcast = (state) =>
+ {
+ lock (_services.SyncRoot)
+ {
+ foreach (WebSocketService service in _services)
+ {
+ service.Ping(data);
+ }
+ }
+ };
+ ThreadPool.QueueUserWorkItem(broadcast);
+ }
+
+ public void RemoveService(WebSocketService service)
+ {
+ _services.Remove(service);
+ }
+
public void Send(byte[] data)
{
WaitCallback broadcast = (state) =>
{
- lock (_webSockets.SyncRoot)
+ lock (_services.SyncRoot)
{
- foreach (WebSocket ws in _webSockets)
+ foreach (WebSocketService service in _services)
{
- if (ws.ReadyState == WsState.OPEN)
- {
- ws.Send(data);
- }
+ service.Send(data);
}
}
};
@@ -206,14 +228,11 @@ namespace WebSocketSharp
{
WaitCallback broadcast = (state) =>
{
- lock (_webSockets.SyncRoot)
+ lock (_services.SyncRoot)
{
- foreach (WebSocket ws in _webSockets)
+ foreach (WebSocketService service in _services)
{
- if (ws.ReadyState == WsState.OPEN)
- {
- ws.Send(data);
- }
+ service.Send(data);
}
}
};
@@ -229,7 +248,7 @@ namespace WebSocketSharp
public void Stop()
{
_tcpListener.Stop();
- Close(CloseStatusCode.NORMAL, String.Empty);
+ Close();
}
#endregion
diff --git a/websocket-sharp/Server/WebSocketService.cs b/websocket-sharp/Server/WebSocketService.cs
new file mode 100644
index 00000000..fee0f19f
--- /dev/null
+++ b/websocket-sharp/Server/WebSocketService.cs
@@ -0,0 +1,130 @@
+#region MIT License
+/**
+ * WebSocketService.cs
+ *
+ * The MIT License
+ *
+ * Copyright (c) 2012 sta.blockhead
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#endregion
+
+using System;
+using WebSocketSharp.Frame;
+
+namespace WebSocketSharp.Server
+{
+ public abstract class WebSocketService
+ {
+ #region Properties
+
+ public IWebSocketServer Server { get; private set; }
+ public WebSocket Socket { get; private set; }
+
+ #endregion
+
+ #region Public Constructor
+
+ public WebSocketService()
+ {
+ }
+
+ #endregion
+
+ #region Private Method
+
+ private void defaultBind()
+ {
+ Socket.OnOpen += (sender, e) =>
+ {
+ Server.AddService(this);
+ };
+ }
+
+ #endregion
+
+ #region Protected Methods
+
+ protected virtual void onOpen(object sender, EventArgs e)
+ {
+ }
+
+ protected virtual void onMessage(object sender, MessageEventArgs e)
+ {
+ }
+
+ protected virtual void onError(object sender, ErrorEventArgs e)
+ {
+ }
+
+ protected virtual void onClose(object sender, CloseEventArgs e)
+ {
+ Server.RemoveService(this);
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ public void Bind(IWebSocketServer server, WebSocket socket)
+ {
+ Server = server;
+ Socket = socket;
+
+ defaultBind();
+ Socket.OnOpen += onOpen;
+ Socket.OnMessage += onMessage;
+ Socket.OnError += onError;
+ Socket.OnClose += onClose;
+ }
+
+ public void Close()
+ {
+ Socket.Close();
+ }
+
+ public void Close(CloseStatusCode code, string reason)
+ {
+ Socket.Close(code, reason);
+ }
+
+ public void Open()
+ {
+ Socket.Connect();
+ }
+
+ public void Ping(string data)
+ {
+ Socket.Ping(data);
+ }
+
+ public void Send(byte[] data)
+ {
+ Socket.Send(data);
+ }
+
+ public void Send(string data)
+ {
+ Socket.Send(data);
+ }
+
+ #endregion
+ }
+}
diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs
index 8bc6157a..dbea36a4 100644
--- a/websocket-sharp/WebSocket.cs
+++ b/websocket-sharp/WebSocket.cs
@@ -748,16 +748,10 @@ namespace WebSocketSharp
private void messageLoop()
{
- #if DEBUG
- Console.WriteLine("\nWS: Info@messageLoop: Current thread IsBackground?: {0}", Thread.CurrentThread.IsBackground);
- #endif
while (_readyState == WsState.OPEN)
{
message();
}
- #if DEBUG
- Console.WriteLine("WS: Info@messageLoop: Exit messageLoop method.");
- #endif
}
private void startMessageThread()
diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll
index a3c86269..20929dc0 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 83a06f05..8539c648 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 e318f2b9..922e8243 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 8e296ffa..62ee767a 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 c41cbdc8..edcbe95f 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 9541e270..8637619b 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.csproj b/websocket-sharp/websocket-sharp.csproj
index f55abe96..5b2a3be6 100644
--- a/websocket-sharp/websocket-sharp.csproj
+++ b/websocket-sharp/websocket-sharp.csproj
@@ -72,14 +72,16 @@
-
-
+
+
+
+
\ No newline at end of file
diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb
index b0b7ab54..752c6e3a 100644
Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ