public void Init(string host, int port, int index, bool littleEnd) { try { //if (inited) if (tcpSession != null) { tcpSession.Close(); tcpSession = null; } //if (!inited) { adapter = new NetAdapter(); adapter.SetEndianness(littleEnd); netClientId = index; socketStatus = SocketStatus.NotConnet; currentHost = host; currentPort = port; IPAddress ipEndPoint = IPAddress.Parse(currentHost); IPEndPoint ipEnd = new IPEndPoint(ipEndPoint, currentPort); tcpSession = new AsyncTcpSession(ipEnd); tcpSession.Connected += onConnected; tcpSession.Closed += onClosed; tcpSession.Error += onError; tcpSession.DataReceived += OnDataReceive; } } catch (System.Exception e) { Debugger.LogError("net client init exception->" + host + "^" + port + "^" + index + "^" + littleEnd + "^" + e.ToString()); } inited = true; }
public void Init(InnerNetNode node, int cs, bool littleEnd) { if (!inited) { netNode = node; csNetGID = cs; adapter = new NetAdapter(); adapter.SetEndianness(littleEnd); inited = true; } }