SocketClient .OnReconnect Bug.fix

Fuhaifeng 2020-12-21 17:34:55 +08:00
parent 119a64143a
commit 0b72d3a042
6 changed files with 36 additions and 43 deletions

View File

@ -11583,8 +11583,8 @@ MonoBehaviour:
size: 1244 size: 1244
- id: 2893 - id: 2893
fileName: lzma/luabytes.unity3d fileName: lzma/luabytes.unity3d
crc: 993108505 crc: 2306403141
size: 6098678 size: 6100161
- id: 2894 - id: 2894
fileName: lzma/resconfigs.unity3d fileName: lzma/resconfigs.unity3d
crc: 4059228276 crc: 4059228276

View File

@ -912,8 +912,8 @@ MonoBehaviour:
settingInfo: settingInfo:
logLevel: 0 logLevel: 0
isDebug: 0 isDebug: 0
bundleMode: 0 bundleMode: 1
luaBundleMode: 0 luaBundleMode: 1
isUpdate: 0 isUpdate: 0
isSDK: 0 isSDK: 0
isSDKLogin: 0 isSDKLogin: 0

View File

@ -132,10 +132,8 @@ public class SocketClient
/// </summary> /// </summary>
public void Connect() public void Connect()
{ {
//Debug.Log("****Socket*********************Connect ---" + IpAddress); //Debug.Log("****Socket*********************Connect ---" + IpAddress);
Close(); Close();
try try
{ {
var ipType = GetIPAddressType(IpAddress); var ipType = GetIPAddressType(IpAddress);
@ -633,15 +631,6 @@ public class SocketClient
float _LastReconectime = 0; float _LastReconectime = 0;
public void TryReconnect() public void TryReconnect()
{ {
//if (m_isConnecting)
// return;
if (client != null && client.Connected)
{
_DoReconnected();
return;
}
if (Time.time - _LastReconectime < AppConst.ConnectTimeout+1) if (Time.time - _LastReconectime < AppConst.ConnectTimeout+1)
return; return;
@ -735,27 +724,30 @@ public class SocketClient
void OnReconnect(IAsyncResult result) void OnReconnect(IAsyncResult result)
{ {
m_isConnecting = false; m_isConnecting = false;
if (!client.Connected)
//检测是否成功的建立了链接。..
if (client==null || !client.Connected)
{ {
Debug.Log("****Socket*********************OnReconnect FAILED ---" + IpAddress); Debug.Log("****Socket*********************OnReconnect FAILED ---" + IpAddress);
return; return;
} }
Debug.Log("****Socket*********************OnReconnect SUCCESS ---" + IpAddress); try
WAIT.AddWait(1f).Wait(()=>
{ {
_DoReconnected(); //完成本次链接
}); client.EndConnect(result);
} // 记录链接的成功事件。
void _DoReconnected()
{
Debug.Log("****Socket*********************AddStateInfo NetworkStateType.Reconnected-" + IpAddress);
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);
Debug.Log("****Socket*********************OnReconnect SUCCESS ---" + IpAddress);
} }
catch(Exception e)
{
Debug.Log("****Socket*********************OnReconnect FAILED ---" + e.Message);
}
}
/// <summary> /// <summary>
/// 发送消息 /// 发送消息

View File

@ -88,19 +88,20 @@ function Network:OnReconnect()
self.socket:SendMessageWithCallBack(MessageTypeProto_pb.RECONNECT_REQUEST, MessageTypeProto_pb.RECONNECT_RESPONSE, nil, function(b) self.socket:SendMessageWithCallBack(MessageTypeProto_pb.RECONNECT_REQUEST, MessageTypeProto_pb.RECONNECT_RESPONSE, nil, function(b)
-- Log("已经重连!!")
-- RequestPanel.Hide()
-- self.isConnected = true
-- self.bIsStartListenHeartBeat = true
-- Game.GlobalEvent:DispatchEvent(Protocal.Connect, self)
end)
Log("已经重连!!") Log("已经重连!!")
RequestPanel.Hide() RequestPanel.Hide()
self.isConnected = true self.isConnected = true
self.bIsStartListenHeartBeat = true self.bIsStartListenHeartBeat = true
Game.GlobalEvent:DispatchEvent(Protocal.Connect, self) Game.GlobalEvent:DispatchEvent(Protocal.Connect, self)
end)
coroutine.start(function()
coroutine.wait(2)
Log("没有收到 重连信息,重新设置链接!!")
if not self.isConnected then
self.socket:Disconnect()
end
end)
end end
function Network:Reset() function Network:Reset()

View File

@ -1 +1 @@
{"subChannel":"1", "buglyId":"261348dcd3", "channel":"pc", "resUrl":"http://60.1.1.12/jieling_dl/dev/assetBundles/subChannal094-test/", "packageVersion":"0.2", "version":"0.15.0", "serverUrl":"http://60.1.1.23:8080/"} {"buglyId":"261348dcd3", "channel":"pc", "resUrl":"http://60.1.1.12/jieling_dl/dev/assetBundles/subChannal094-test/", "packageVersion":"0.2", "subChannel":"1", "version":"0.15.0", "serverUrl":"http://60.1.1.23:8080/"}

View File

@ -120,7 +120,7 @@ PlayerSettings:
16:10: 1 16:10: 1
16:9: 1 16:9: 1
Others: 1 Others: 1
bundleVersion: 0.1F bundleVersion: 0.1G
preloadedAssets: [] preloadedAssets: []
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0