diff --git a/Tesses.WebServer.WebSocket/Class1.cs b/Tesses.WebServer.WebSocket/Class1.cs index 7451b17..ea693d0 100644 --- a/Tesses.WebServer.WebSocket/Class1.cs +++ b/Tesses.WebServer.WebSocket/Class1.cs @@ -210,7 +210,7 @@ namespace Tesses.WebServer.WebSocket public class WebSocketServer { - Mutex mtx=new Mutex(); + SemaphoreSlim semaphoreSlim=new SemaphoreSlim(1,1); bool hasInit=false; ServerContext context; public WebSocketServer(ServerContext ctx) @@ -248,7 +248,7 @@ namespace Tesses.WebServer.WebSocket { while(!hasInit) ; - mtx.WaitOne(); + await semaphoreSlim.WaitAsync(); int opCode = msg.Binary ? 0x2 : 0x1; @@ -276,12 +276,12 @@ namespace Tesses.WebServer.WebSocket Array.Copy(msg.Data,i*4096,message,1+b.Length,r); await context.NetworkStream.WriteAsync(message,0,message.Length); } - mtx.ReleaseMutex(); + semaphoreSlim.Release(); } private async Task PongSend(byte[] msg,long len) { - mtx.WaitOne(); + await semaphoreSlim.WaitAsync(); int finField = 0b10000000 ; byte firstByte= (byte)(finField | 0xA); @@ -291,7 +291,7 @@ namespace Tesses.WebServer.WebSocket Array.Copy(b,0,message,1,b.Length); Array.Copy(msg,0,message,1+b.Length,len); await context.NetworkStream.WriteAsync(message,0,message.Length); - mtx.ReleaseMutex(); + semaphoreSlim.Release(); } private string get_Sec_WebSocketAccept(string headerVal) { @@ -328,7 +328,7 @@ namespace Tesses.WebServer.WebSocket public async Task Ping(byte[] ping) { - mtx.WaitOne(); + await semaphoreSlim.WaitAsync(); int finField = 0b10000000 ; byte firstByte= (byte)(finField | 0x9); @@ -338,7 +338,7 @@ namespace Tesses.WebServer.WebSocket Array.Copy(b,0,message,1,b.Length); Array.Copy(ping,0,message,1+b.Length,ping.Length); await context.NetworkStream.WriteAsync(message,0,message.Length); - mtx.ReleaseMutex(); + semaphoreSlim.Release(); } private async Task get_short() { diff --git a/Tesses.WebServer.WebSocket/Tesses.WebServer.WebSocket.csproj b/Tesses.WebServer.WebSocket/Tesses.WebServer.WebSocket.csproj index d2ac7e9..e04440d 100644 --- a/Tesses.WebServer.WebSocket/Tesses.WebServer.WebSocket.csproj +++ b/Tesses.WebServer.WebSocket/Tesses.WebServer.WebSocket.csproj @@ -5,9 +5,9 @@ Tesses.WebServer.WebSocket Mike Nolan Tesses - 1.0.1 - 1.0.1 - 1.0.1 + 1.0.1.1 + 1.0.1.1 + 1.0.1.1 WebSockets for Tesses.WebServer MIT HTTP, WebServer, Website, WebSockets