再次尝试修复同时连接两个socket的问题

gaoxin 2020-09-10 18:09:30 +08:00
parent 85a8d95d19
commit 41aa573c68
4 changed files with 28 additions and 3 deletions

View File

@ -93,6 +93,12 @@ namespace GameLogic
return socket;
}
public void RemoveSocket(SocketClient sc)
{
sc.Close();
socketList.Remove(sc);
}
public void SendGetHttp(string url, LuaFunction callback, Action<string> sharpFunc, Action errorAction, LuaFunction errorLuaFunc)
{
StartCoroutine(HttpGet_Co(url, callback, sharpFunc, errorAction, errorLuaFunc));

View File

@ -436,6 +436,8 @@ public class SocketClient
else if (info.type == NetworkStateType.ConnectFail)
{
Util.CallMethod("SocketManager", "OnConnectFail", this);
// 删除自己
this.netMgr.RemoveSocket(this);
}
else if (info.type == NetworkStateType.Reconnected)
{
@ -446,6 +448,8 @@ public class SocketClient
else if (info.type == NetworkStateType.ReconnectFail)
{
Util.CallMethod("SocketManager", "OnReconnectFail", this);
// 删除自己
this.netMgr.RemoveSocket(this);
}
else if (info.type == NetworkStateType.Disconnect)
{
@ -543,8 +547,9 @@ public class SocketClient
public void Disconnect()
{
//Debug.Log("****Socket*********************Disconnect ---" + IpAddress);
Close(); //关掉客户端链接
Util.CallMethod("SocketManager", "OnDisconnect", this);
// 删除自己
this.netMgr.RemoveSocket(this);
}
private Coroutine checkConnect_co;

View File

@ -275,9 +275,9 @@ function Network:Update()
Game.Logout()
end, function()
-- if self:IsSending() then
self:SetSending(false)
-- self:SetSending(false)
self.resendTimes = 0
self.sendFuncQueue:Clear()
-- self.sendFuncQueue:Clear()
-- end
end, "重新登录")
end

View File

@ -40,6 +40,14 @@ function SocketManager.AddNetwork(type, ipAddress, port)
SocketManager.SocketDic[socket] = network
end
function SocketManager.RemoveNetwork(socket)
-- 删除socket
local network = SocketManager.SocketDic[socket]
SocketManager.SocketDic[socket] = nil
SocketManager.SocketList[network.type] = nil
end
function SocketManager.GetNetwork(type)
return SocketManager.SocketList[type]
end
@ -67,6 +75,8 @@ end
function SocketManager.OnConnectFail(socket)
if SocketManager.SocketDic[socket] then
SocketManager.SocketDic[socket]:OnConnectFail()
-- 删除
SocketManager.RemoveNetwork(socket)
end
end
@ -74,6 +84,8 @@ end
function SocketManager.OnReconnectFail(socket)
if SocketManager.SocketDic[socket] then
SocketManager.SocketDic[socket]:OnReconnectFail()
-- 删除
SocketManager.RemoveNetwork(socket)
end
end
@ -102,6 +114,8 @@ end
function SocketManager.OnDisconnect(socket)
if SocketManager.SocketDic[socket] then
SocketManager.SocketDic[socket]:OnDisconnect()
-- 删除
SocketManager.RemoveNetwork(socket)
end
end