Procházet zdrojové kódy

TCP据说有连接不上的问题,加几个log方便查错

tanghai před 7 roky
rodič
revize
b0a858bb8e

+ 2 - 2
Server/Hotfix/Module/Message/NetOuterComponentSystem.cs

@@ -8,7 +8,7 @@ namespace ETHotfix
 	{
 		public override void Awake(NetOuterComponent self)
 		{
-			self.Awake(NetworkProtocol.KCP);
+			self.Awake(NetworkProtocol.TCP);
 			self.MessagePacker = new ProtobufPacker();
 			self.MessageDispatcher = new OuterMessageDispatcher();
 		}
@@ -19,7 +19,7 @@ namespace ETHotfix
 	{
 		public override void Awake(NetOuterComponent self, IPEndPoint ipEndPoint)
 		{
-			self.Awake(NetworkProtocol.KCP, ipEndPoint);
+			self.Awake(NetworkProtocol.TCP, ipEndPoint);
 			self.MessagePacker = new ProtobufPacker();
 			self.MessageDispatcher = new OuterMessageDispatcher();
 		}

+ 1 - 1
Unity/Assets/Scripts/Module/Message/NetOuterComponent.cs

@@ -22,7 +22,7 @@
 	{
 		public void Awake()
 		{
-			this.Awake(NetworkProtocol.KCP);
+			this.Awake(NetworkProtocol.TCP);
 			this.MessagePacker = new ProtobufPacker();
 			this.MessageDispatcher = new ClientDispatcher();
 		}

+ 19 - 2
Unity/Assets/Scripts/Module/Message/Network/TCP/TChannel.cs

@@ -12,8 +12,8 @@ namespace ETModel
 	public sealed class TChannel: AChannel
 	{
 		private Socket socket;
-		private readonly SocketAsyncEventArgs innArgs = new SocketAsyncEventArgs();
-		private readonly SocketAsyncEventArgs outArgs = new SocketAsyncEventArgs();
+		private SocketAsyncEventArgs innArgs = new SocketAsyncEventArgs();
+		private SocketAsyncEventArgs outArgs = new SocketAsyncEventArgs();
 
 		private readonly CircularBuffer recvBuffer = new CircularBuffer();
 		private readonly CircularBuffer sendBuffer = new CircularBuffer();
@@ -64,6 +64,8 @@ namespace ETModel
 			this.socket.Close();
 			this.innArgs.Dispose();
 			this.outArgs.Dispose();
+			this.innArgs = null;
+			this.outArgs = null;
 			this.socket = null;
 		}
 
@@ -145,10 +147,15 @@ namespace ETModel
 
 		private void OnConnectComplete(object o)
 		{
+			if (this.IsDisposed)
+			{
+				throw new Exception("TChannel已经被Dispose, 不能发送消息");
+			}
 			SocketAsyncEventArgs e = (SocketAsyncEventArgs) o;
 			UserTokenInfo userTokenInfo = (UserTokenInfo) e.UserToken;
 			if (userTokenInfo.InstanceId != this.InstanceId)
 			{
+				Log.Error($"session disposed!");
 				return;
 			}
 
@@ -196,10 +203,15 @@ namespace ETModel
 
 		private void OnRecvComplete(object o)
 		{
+			if (this.IsDisposed)
+			{
+				throw new Exception("TChannel已经被Dispose, 不能发送消息");
+			}
 			SocketAsyncEventArgs e = (SocketAsyncEventArgs)o;
 			UserTokenInfo userTokenInfo = (UserTokenInfo) e.UserToken;
 			if (userTokenInfo.InstanceId != this.InstanceId)
 			{
+				Log.Error($"session disposed!");
 				return;
 			}
 
@@ -287,10 +299,15 @@ namespace ETModel
 
 		private void OnSendComplete(object o)
 		{
+			if (this.IsDisposed)
+			{
+				throw new Exception("TChannel已经被Dispose, 不能发送消息");
+			}
 			SocketAsyncEventArgs e = (SocketAsyncEventArgs)o;
 			UserTokenInfo userTokenInfo = (UserTokenInfo) e.UserToken;
 			if (userTokenInfo.InstanceId != this.InstanceId)
 			{
+				Log.Error($"session disposed!");
 				return;
 			}
 

+ 1 - 0
Unity/Assets/Scripts/Module/Message/Network/TCP/TService.cs

@@ -75,6 +75,7 @@ namespace ETModel
 			UserTokenInfo userTokenInfo = (UserTokenInfo) e.UserToken;
 			if (userTokenInfo.InstanceId != this.InstanceId)
 			{
+				Log.Error($"session disposed!");
 				return;
 			}