protected bool InitTcpClient(IPEndPoint ep) { tcpClient = TcpHostClient.Create(ep); if (tcpClient == null) { return(false); } tcpClient.OnReceive += (ch, buffer) => { OnReceive?.Invoke(this, buffer); }; tcpClient.OnClose += (ch) => { OnClose?.Invoke(this); }; tcpClient.OnException += (ch, ex) => { OnException?.Invoke(this, ex); }; Log.Info(string.Format("init_tcp_client_localaddr@{0}", tcpClient.LocalAddress)); return(true); }
public static TcpHostClient Create(IPEndPoint ep) { var channelConfig = new TcpChannelConfig(); channelConfig.Address = ep; //channelConfig.Address = ep.Address.ToIPv4String(); //channelConfig.Port = ep.Port; #if !UNITY_5_3_OR_NEWER channelConfig.UseLibuv = false; #endif if (client == null) { client = new TcpSocketClient(); if (!client.init(channelConfig)) { client = null; return(null); } } var listener = new TcpHostClient(); listener.clientChannel = client.Connect(ep, listener); if (listener.clientChannel == null) { return(null); } return(listener); }
public static TcpHostClient Create(IPEndPoint ep) { var channelConfig = new TcpChannelConfig(); channelConfig.Address = ep; //channelConfig.Address = ep.Address.ToIPv4String(); //channelConfig.Port = ep.Port; #if !CLIENT channelConfig.UseLibuv = false; #endif var obj = new TcpHostClient(); if (!obj.Init(channelConfig, ep)) { return(null); } return(obj); }