Просмотр исходного кода

kchannel客户端id由一个随机数表示,避免之前的客户端消息串到当前客户端来

tanghai 8 лет назад
Родитель
Сommit
7af7526387
1 измененных файлов с 3 добавлено и 3 удалено
  1. 3 3
      Unity/Assets/Scripts/Base/Network/KNet/KService.cs

+ 3 - 3
Unity/Assets/Scripts/Base/Network/KNet/KService.cs

@@ -16,7 +16,6 @@ namespace Model
 	public sealed class KService : AService
 	{
 		private uint IdGenerater = 1000;
-		private uint IdAccept = 2000000000;
 
 		public uint TimeNow { get; set; }
 
@@ -195,7 +194,7 @@ namespace Model
 
 		private KChannel CreateAcceptChannel(IPEndPoint remoteEndPoint, uint remoteConn)
 		{
-			KChannel channel = new KChannel(--this.IdAccept, remoteConn, this.socket, remoteEndPoint, this);
+			KChannel channel = new KChannel(++this.IdGenerater, remoteConn, this.socket, remoteEndPoint, this);
 			KChannel oldChannel;
 			if (this.idChannels.TryGetValue(channel.Id, out oldChannel))
 			{
@@ -208,7 +207,8 @@ namespace Model
 
 		private KChannel CreateConnectChannel(IPEndPoint remoteEndPoint)
 		{
-			KChannel channel = new KChannel(++this.IdGenerater, this.socket, remoteEndPoint, this);
+			uint conv = (uint)RandomHelper.RandomNumber(1000, int.MaxValue);
+			KChannel channel = new KChannel(conv, this.socket, remoteEndPoint, this);
 			KChannel oldChannel;
 			if (this.idChannels.TryGetValue(channel.Id, out oldChannel))
 			{