public bool Init(TcpChannelConfig channelConfig, IPEndPoint ep) { if (client == null) { lock (lockObj) { if (client == null) { client = new TcpSocketClient(); if (!client.init(channelConfig)) { client = null; return(false); } } } } this.clientChannel = client.Connect(ep, this); if (this.clientChannel == null) { return(false); } 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 TcpHostServer Create(IPEndPoint ep) //{ // return Create(ep.Address.ToIPv4String(), ep.Port); //} public bool Init(TcpChannelConfig channelConfig, IPEndPoint ep) { server = new TcpSocketServer(); if (!server.Start(channelConfig, this)) { return(false); } return(true); }
public static TcpHostServer Create(IPEndPoint ep) { var channelConfig = new TcpChannelConfig(); channelConfig.Address = ep;// ip;// "0.0.0.0"; //channelConfig.Port = port; #if !UNITY_5_3_OR_NEWER channelConfig.UseLibuv = true; #endif var obj = new TcpHostServer(); if (!obj.Init(channelConfig, ep)) { return(null); } return(obj); }
//public static TcpHostServer Create(IPEndPoint ep) //{ // return Create(ep.Address.ToIPv4String(), ep.Port); //} public static TcpHostServer Create(IPEndPoint ep) { var channelConfig = new TcpChannelConfig(); channelConfig.Address = ep;// ip;// "0.0.0.0"; //channelConfig.Port = port; #if !UNITY_5_3_OR_NEWER channelConfig.UseLibuv = true; #endif var listener = new TcpHostServer(); var server = new TcpSocketServer(); if (!server.Start(channelConfig, listener)) { return(null); } return(listener); }
public virtual void Initialize(TcpChannelConfig config) { Socket = config.Socket; _remoteEndPoint = Socket.RemoteEndPoint; _localEndPoint = Socket.LocalEndPoint; _channelConfig = config; _sendArgs = config.SocketAsyncEventPool.Pull(); _sendArgs.Completed += WriteCompleted; _readArgs = config.SocketAsyncEventPool.Pull(); _readArgs.Completed += ReadCompleted; _readSlice = config.BufferManager.AssignBufferTo(_readArgs); _readSlice.Count = 0; //_inbufferStream = new MemoryStream(_readArgs.Buffer, _readArgs.Offset, _readArgs.Count); //_inbufferStream.SetLength(0); Initialize(); }
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); }
private void OnAcceptSocket(IAsyncResult ar) { try { Socket socket = _listener.EndAcceptSocket(ar); var client = new TcpServerChildChannel(ChildPipeline); var config = new TcpChannelConfig(_bufferManager, _argsPool) {Socket = socket}; client.Initialize(config); SendUpstream(new AcceptedEvent {ClientChannel = client}); } catch (Exception err) { HandleException(err); } }