少年修仙传客户端代码仓库
client_Zxw
2018-09-25 4dba76710a47cb8c83c5cf7f7b96702c702c5039
Core/NetworkPackage/Socket/ClientSocketController.cs
@@ -9,7 +9,8 @@
public class ClientSocketController
{
    Socket m_Socket;
    public Socket socket {
    public Socket socket
    {
        get { return m_Socket; }
    }
@@ -43,7 +44,7 @@
        }
        catch (Exception e)
        {
            DesignDebug.LogError(e.Message);
            DebugEx.LogError(e.Message);
        }
    }
@@ -53,12 +54,12 @@
        if (ipAddresses[0].AddressFamily == AddressFamily.InterNetworkV6)
        {
            DesignDebug.Log("当前使用的网络: IPV6");
            DebugEx.Log("当前使用的网络: IPV6");
            m_Socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
        }
        else
        {
            DesignDebug.Log("当前使用的网络: IPV4");
            DebugEx.Log("当前使用的网络: IPV4");
            m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        }
@@ -81,14 +82,14 @@
    {
        if (!_result.IsCompleted)
        {
            DesignDebug.Log("链接超时!");
            DebugEx.Log("链接超时!");
            CloseConnect();
        }
        else
        {
            if (m_Socket != null && m_Socket.Connected)
            {
                DesignDebug.Log("确认的链接实现");
                DebugEx.Log("确认的链接实现");
                OnConnectSuccess();
                if (onConnected != null)
@@ -114,16 +115,31 @@
    /// </summary>
    public void CloseConnect()
    {
        isStopTreading = true;
        if (m_packageThread != null)
        try
        {
            m_packageThread.Abort();
            isStopTreading = true;
            if (m_packageThread != null)
            {
                m_packageThread.Abort();
            }
        }
        catch (System.Exception ex)
        {
            DebugEx.Log(ex);
        }
        if (m_Socket != null && m_Socket.Connected)
        try
        {
            m_Socket.Shutdown(SocketShutdown.Both);
            m_Socket.Close();
            if (m_Socket != null && m_Socket.Connected)
            {
                m_Socket.Shutdown(SocketShutdown.Both);
                m_Socket.Close();
            }
        }
        catch (System.Exception ex)
        {
            DebugEx.Log(ex);
        }
        sendQueue.Clear();
@@ -183,7 +199,7 @@
            }
            catch (Exception e)
            {
                DesignDebug.Log(e);
                DebugEx.Log(e);
            }
        }
@@ -236,9 +252,9 @@
                vNetpack = PackageRegedit.TransPack(vPackBytes);
                if (vNetpack != null)
                {
                    if (DesignDebug.EnableNet)
                    if (DebugEx.EnableNetLog)
                    {
                        DesignDebug.LogNetFormat("收包:{0}", vNetpack.GetType().Name);
                        DebugEx.NetLogFormat("收包:{0}", vNetpack.GetType().Name);
                    }
                    GameNetSystem.Instance.PushPackage(vNetpack);
@@ -263,13 +279,13 @@
            return;
        if (vNetPack == null)
        {
            DesignDebug.LogError("要发的信息对象为空");
            DebugEx.LogError("要发的信息对象为空");
            return;
        }
        if (DesignDebug.EnableNet)
        if (DebugEx.EnableNetLog)
        {
            DesignDebug.LogNetFormat("发包:{0}", vNetPack.GetType().Name);
            DebugEx.NetLogFormat("发包:{0}", vNetPack.GetType().Name);
        }
        if (vNetPack.cmd == (ushort)0x03FE || vNetPack.cmd == (ushort)0x1801)
@@ -296,12 +312,12 @@
    {
        if (!Connected)
        {
            DesignDebug.LogError("尚未与该后端链接!无法发送信息");
            DebugEx.LogError("尚未与该后端链接!无法发送信息");
            return;
        }
        if (vBytes == null || vBytes.Length < 2)
        {
            DesignDebug.LogError("要发的信息数据为空或数据不足");
            DebugEx.LogError("要发的信息数据为空或数据不足");
            return;
        }
@@ -324,12 +340,12 @@
    {
        if (!Connected)
        {
            DesignDebug.LogError("尚未与该后端链接!无法发送信息");
            DebugEx.LogError("尚未与该后端链接!无法发送信息");
            return;
        }
        if (vBytes == null || vBytes.Length < 2)
        {
            DesignDebug.LogError("要发的信息数据为空或数据不足");
            DebugEx.LogError("要发的信息数据为空或数据不足");
            return;
        }
@@ -353,7 +369,7 @@
        }
        catch
        {
            DesignDebug.LogError("发送时发生异常");
            DebugEx.LogError("发送时发生异常");
        }
    }
@@ -373,7 +389,7 @@
        }
        catch (Exception ex)
        {
            DesignDebug.Log(ex);
            DebugEx.Log(ex);
        }
    }