检测 重连后 和服务端的 确认消息 11700 11701

dev_chengFeng
Fuhaifeng 2021-01-06 20:57:59 +08:00
parent 18642e01ae
commit dc04060dd9
1 changed files with 16 additions and 15 deletions

View File

@ -403,7 +403,7 @@ public class SocketClient
buffer.ReadIntToByte(); buffer.ReadIntToByte();
//协议号 //协议号
int msgid = buffer.ReadIntToByte(); int msgid = buffer.ReadIntToByte();
Debug.Log("[SocketClient:OnReceivedMessage]msgid:" + msgid);
//收到心跳包 //收到心跳包
if (msgid == 1001) if (msgid == 1001)
{ {
@ -441,13 +441,10 @@ public class SocketClient
UnregistNetMessage(INDICATION_ERROR_CODE, Ygqmgx_indicationErrorAction); UnregistNetMessage(INDICATION_ERROR_CODE, Ygqmgx_indicationErrorAction);
if (client != null) if (client != null)
{ {
try try
{ {
client.Client.Disconnect(false); client.Client.Disconnect(false);
Debug.Log("****Socket*********************Disconnect() ---" + client.Client.Handle+ "@"+ client.Client.LocalEndPoint.ToString()); //Debug.Log("****Socket*********************Disconnect() ---" + client.Client.Handle+ "@"+ client.Client.LocalEndPoint.ToString());
} }
catch { } catch { }
@ -706,20 +703,22 @@ public class SocketClient
float _LastReconectime = 0; float _LastReconectime = 0;
public void TryReconnect() public void TryReconnect()
{ {
if (Time.time - _LastReconectime < AppConst.ConnectTimeout + 1) if (IsConnected())
{
NetworkStateInfo info = new NetworkStateInfo();
info.type = NetworkStateType.Reconnected;
info.msg = null;
stateInfoStack.Push(info);
return;
}
if (Time.time - _LastReconectime < AppConst.ConnectTimeout )
return; return;
_LastReconectime = Time.time; _LastReconectime = Time.time;
Debug.Log("****Socket*********************TryReconnect ---" + IpAddress); Debug.Log("****Socket*********************TryReconnect ---" + IpAddress);
//if (IsConnected())
//{
// NetworkStateInfo info = new NetworkStateInfo();
// info.type = NetworkStateType.Reconnected;
// info.msg = null;
// stateInfoStack.Push(info);
// return;
//}
if (reconnect_co != null) if (reconnect_co != null)
@ -803,6 +802,7 @@ public class SocketClient
void OnReconnect(IAsyncResult result) void OnReconnect(IAsyncResult result)
{ {
_LastReconectime = 0;
m_isConnecting = false; m_isConnecting = false;
//检测是否成功的建立了链接。.. //检测是否成功的建立了链接。..
@ -820,6 +820,7 @@ public class SocketClient
outStream = client.GetStream(); outStream = client.GetStream();
client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null); client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
AddStateInfo(NetworkStateType.Reconnected, null); AddStateInfo(NetworkStateType.Reconnected, null);
_LastReconectime = 0;
Debug.Log("****Socket*********************OnReconnect SUCCESS @"+ client.Client.LocalEndPoint.ToString()); Debug.Log("****Socket*********************OnReconnect SUCCESS @"+ client.Client.LocalEndPoint.ToString());
} }
catch (Exception e) catch (Exception e)
@ -861,7 +862,7 @@ public class SocketClient
buffer.Close(); buffer.Close();
//UnityEngine.Debug.Log("SocketClient.m_SendMessage..."+ msgId); Debug.Log("[SocketClient.m_SendMessage]..."+ msgId);
} }
/// <summary> /// <summary>