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
- id: 2893
fileName: lzma/luabytes.unity3d
crc: 993108505
size: 6098678
crc: 2306403141
size: 6100161
- id: 2894
fileName: lzma/resconfigs.unity3d
crc: 4059228276

View File

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

View File

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

View File

@ -88,19 +88,20 @@ function Network:OnReconnect()
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)
Log("已经重连!!")
RequestPanel.Hide()
self.isConnected = true
self.bIsStartListenHeartBeat = true
Game.GlobalEvent:DispatchEvent(Protocal.Connect, self)
end)
Log("已经重连!!")
RequestPanel.Hide()
self.isConnected = true
self.bIsStartListenHeartBeat = true
Game.GlobalEvent:DispatchEvent(Protocal.Connect, self)
coroutine.start(function()
coroutine.wait(2)
Log("没有收到 重连信息,重新设置链接!!")
if not self.isConnected then
self.socket:Disconnect()
end
end)
end
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:9: 1
Others: 1
bundleVersion: 0.1F
bundleVersion: 0.1G
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0