LUA 中校验被提出的合理检查
parent
3819ed162a
commit
18642e01ae
|
@ -231,7 +231,7 @@ public class SocketClient
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int _NNN;
|
||||
/// <summary>
|
||||
/// 读取消息
|
||||
/// </summary>
|
||||
|
@ -240,11 +240,18 @@ public class SocketClient
|
|||
int bytesRead = 0;
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
//System.Net.Sockets.Socket.SocketAsyncResult
|
||||
//NetBug.Fix by FHF..
|
||||
//甄别socket当前是否正在连接中,避免重连的间隔内收到服务端消息。.
|
||||
if (client == null || !client.Connected)
|
||||
return;
|
||||
|
||||
//int ilen = client.GetStream().EndRead(asr);
|
||||
// Debug.Log("[SocketClient] From Socket: EndRead.Len:" + ilen);
|
||||
|
||||
|
||||
lock (client.GetStream())
|
||||
{
|
||||
//读取字节流到缓冲区
|
||||
|
@ -257,6 +264,8 @@ public class SocketClient
|
|||
AddStateInfo(NetworkStateType.Disconnect, "bytesRead < 1");
|
||||
return;
|
||||
}
|
||||
Debug.Log("[SocketClient] NowClient:@" + ++_NNN+" _:"+bytesRead + ":" + client.Client.Handle);
|
||||
|
||||
OnReceive(byteBuffer, bytesRead); //分析数据包内容,抛给逻辑层
|
||||
lock (client.GetStream())
|
||||
{
|
||||
|
@ -265,7 +274,7 @@ public class SocketClient
|
|||
client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
|
||||
}
|
||||
|
||||
Debug.Log("SocketClient.OnRead " + byteBuffer.ToString());
|
||||
//Debug.Log("SocketClient.OnRead " + byteBuffer.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -427,18 +436,31 @@ public class SocketClient
|
|||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
Debug.Log("****Socket*********************Close ---" + IpAddress);
|
||||
|
||||
//确保 关闭Client的链接状态。
|
||||
UnregistNetMessage(INDICATION_ERROR_CODE, Ygqmgx_indicationErrorAction);
|
||||
if (client != null)
|
||||
{
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
client.Client.Disconnect(false);
|
||||
Debug.Log("****Socket*********************Disconnect() ---" + client.Client.Handle+ "@"+ client.Client.LocalEndPoint.ToString());
|
||||
}
|
||||
catch { }
|
||||
|
||||
Debug.Log("****Socket*********************Close ---" + client.Client.Handle);
|
||||
try
|
||||
{
|
||||
client.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
client = null;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -719,6 +741,7 @@ public class SocketClient
|
|||
var ipType = GetIPAddressType(IpAddress);
|
||||
client = null;
|
||||
client = new TcpClient(ipType);
|
||||
Debug.Log("****Socket*********************NEW ---" + client.Client.Handle);
|
||||
//client.SendTimeout = 1000;
|
||||
//client.ReceiveTimeout = 1000;
|
||||
client.NoDelay = true;
|
||||
|
@ -797,7 +820,7 @@ public class SocketClient
|
|||
outStream = client.GetStream();
|
||||
client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
|
||||
AddStateInfo(NetworkStateType.Reconnected, null);
|
||||
Debug.Log("****Socket*********************OnReconnect SUCCESS ---" + IpAddress);
|
||||
Debug.Log("****Socket*********************OnReconnect SUCCESS @"+ client.Client.LocalEndPoint.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,8 @@ function Network.New(type, socket)
|
|||
instance.re_sendWaitTime = 0 --记录断线等待时间(秒)
|
||||
instance.re_maxSendWaitTime = 5 --消息断线重发等待时间(秒),超过该时间会重连
|
||||
|
||||
instance.ReconnectTime=0 -- 重连的发生时间
|
||||
|
||||
setmetatable(instance, Network)
|
||||
return instance
|
||||
end
|
||||
|
@ -66,6 +68,7 @@ function Network:OnDisconnect(err)
|
|||
|
||||
RequestPanel.Show("您已掉线,正在请求重连")--..err)
|
||||
self.socket:TryReconnect()
|
||||
self.ReconnectTime= Time.time
|
||||
end
|
||||
|
||||
function Network:SendClientHeartBeat()
|
||||
|
@ -231,6 +234,10 @@ function Network:ReceiveErrorInfo(buffer)
|
|||
end
|
||||
else
|
||||
if msg.errCode == -101 or msg.errCode == -102 then
|
||||
|
||||
if(Time.time- self.ReconnectTime<10)then
|
||||
return
|
||||
end
|
||||
--被顶号或者被封号
|
||||
Game.Logout()
|
||||
AppConst.Code = msg.errMsg --TODO:重登会重置所有lua变量信息,用一个不用的C#变量记录,用于记录异常退出信息
|
||||
|
|
Loading…
Reference in New Issue