public bool Connect(string networkAddress, int networkPort) { if (IsConnected) { Debug.LogError("client is connected!"); return(false); } if (ConnectState == NetConnectState.Connecting) { return(false); } ConnectState = NetConnectState.Connecting; this.networkAddress = networkAddress; this.networkPort = networkPort; if (LogInfo) { Debug.Log("Client connecting to " + networkAddress + ":" + networkPort); } if (transport.Connect(networkAddress, networkPort)) { //if (LogInfo) Debug.Log("[" + name + "] LiteNetLibManager::Client Connect"); if (OnStartClient != null) { OnStartClient(); } return(true); } return(false); }
// 游戏服务器 public static void ConnectGameServer() { ProtoMsg.MsgNetAddress address = LoginDC.GetGameServerNetInfo(); if (address == null) { IGGDebug.Log("未获取游戏服务器ip"); return; } // 发送登录请求 Communicate.Disconnect(); if (Communicate.IsConnected() == false) { Communicate.SetGSConnetorGame(true); NetConnectState.SetConnetOverTime(3.0f, OnConnectOverTime); string ip = address.u32Ip.ToString(); if (!isDomainAddrIp(address.u32Ip.ToString().ToCharArray())) { // data.netAdd.ip 转 ip 地址 ip = IntToIp((Int32)address.u32Ip); } IGGDebug.Log("游戏服务器:" + ip + "," + address.u32Port); Communicate.Connect2GS(ip, (int)address.u32Port); } }
private void SetNetConnectState(NetConnectState m_connectState, EDisconnectInfo info) { this.m_connectState = m_connectState; if (OnNetConnectStateChange != null) { OnNetConnectStateChange(m_connectState, info); } }
private void OnNetConnectStateChange(NetConnectState state, EDisconnectInfo arg2) { if (state == NetConnectState.DisConnected) { //Debug.Log("断开连接!"); RemovePlayer(); } }
protected override void PeerConnectedEvent(long connectionId) { Debug.Log("Client Peer Connected ! connectionId :" + connectionId); IsConnected = true; ConnectionId = connectionId; ConnectState = NetConnectState.Connected; if (OnClientConnected != null) { OnClientConnected(); } }
protected override void DisconnectedEvent(long connectionId, DisconnectInfo disconnectInfo) { Debug.Log("Client DisconnectedEvent :" + connectionId + " disconnectInfo:" + disconnectInfo.Reason); IsConnected = false; ConnectState = NetConnectState.DisConnected; if (OnDisconnected != null) { OnDisconnected(disconnectInfo); } }
// 登录服务器 public static void ConnectLoginServer() { // 发送登录请求 if (Communicate.IsConnected() == false) { Communicate.Disconnect(); Communicate.SetGSConnetorGame(false); NetConnectState.SetConnetOverTime(3.0f, OnConnectOverTime); //Communicate.Connect2GS(g_ip, g_port); ServerInfo sInfo = GetServerInfo(); if (null != sInfo) { Communicate.Connect2GS(sInfo.iP, sInfo.Port); } else { IGGDebug.Log("未获取登入服务器ip"); } } }
private void SetNetConnectState(NetConnectState m_connectState) { SetNetConnectState(m_connectState, default(EDisconnectInfo)); }