Jelajahi Sumber

修复Websocket中的问题

tanghai 2 tahun lalu
induk
melakukan
be9abbcb61

+ 5 - 0
Unity/Assets/Scripts/Core/Network/WChannel.cs

@@ -4,6 +4,7 @@ using System.IO;
 using System.Net;
 using System.Net;
 using System.Net.WebSockets;
 using System.Net.WebSockets;
 using System.Threading;
 using System.Threading;
+using System.Threading.Tasks;
 
 
 namespace ET
 namespace ET
 {
 {
@@ -154,6 +155,10 @@ namespace ET
                             return;
                             return;
                         }
                         }
                     }
                     }
+                    catch (TaskCanceledException e)
+                    {
+                        Log.Warning(e.ToString());
+                    }
                     catch (Exception e)
                     catch (Exception e)
                     {
                     {
                         Log.Error(e);
                         Log.Error(e);

+ 10 - 11
Unity/Assets/Scripts/Core/Network/WService.cs

@@ -1,6 +1,6 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
-using System.IO;
+using System.Linq;
 using System.Net;
 using System.Net;
 using System.Net.WebSockets;
 using System.Net.WebSockets;
 
 
@@ -16,18 +16,18 @@ namespace ET
 
 
         public ThreadSynchronizationContext ThreadSynchronizationContext;
         public ThreadSynchronizationContext ThreadSynchronizationContext;
 
 
-        public WService(IEnumerable<string> prefixs, ILog log): base(log)
+        public WService(ThreadSynchronizationContext threadSynchronizationContext, IEnumerable<string> prefixs, ILog log): base(log)
         {
         {
-            this.ThreadSynchronizationContext = new ThreadSynchronizationContext();
+            this.ThreadSynchronizationContext = threadSynchronizationContext;
             
             
             this.httpListener = new HttpListener();
             this.httpListener = new HttpListener();
 
 
             StartAccept(prefixs).Coroutine();
             StartAccept(prefixs).Coroutine();
         }
         }
         
         
-        public WService(ILog log): base(log)
+        public WService(ThreadSynchronizationContext threadSynchronizationContext, ILog log): base(log)
         {
         {
-            this.ThreadSynchronizationContext = new ThreadSynchronizationContext();
+            this.ThreadSynchronizationContext = threadSynchronizationContext;
         }
         }
         
         
         private long GetId
         private long GetId
@@ -45,6 +45,10 @@ namespace ET
             this.channels[channel.Id] = channel;
             this.channels[channel.Id] = channel;
         }
         }
 
 
+        public override void Update()
+        {
+        }
+
         public override void Remove(long id, int error = 0)
         public override void Remove(long id, int error = 0)
         {
         {
             WChannel channel;
             WChannel channel;
@@ -116,7 +120,7 @@ namespace ET
             {
             {
                 if (e.ErrorCode == 5)
                 if (e.ErrorCode == 5)
                 {
                 {
-                    throw new Exception($"CMD管理员中输入: netsh http add urlacl url=http://*:8080/ user=Everyone", e);
+                    throw new Exception($"CMD管理员中输入: netsh http add urlacl url=http://*:8080/ user=Everyone   {prefixs.ToList().ListToString()}", e);
                 }
                 }
 
 
                 Log.Error(e);
                 Log.Error(e);
@@ -136,10 +140,5 @@ namespace ET
             }
             }
             channel.Send(message);
             channel.Send(message);
         }
         }
-
-        public override void Update()
-        {
-            this.ThreadSynchronizationContext.Update();
-        }
     }
     }
 }
 }