public override AChannel ConnectChannel(IPEndPoint ipEndPoint) { TChannel channel = new TChannel(ipEndPoint, this); this.idChannels[channel.Id] = channel; return(channel); }
private void OnAcceptComplete(object o) { if (this.acceptor == null) { return; } SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; if (e.SocketError != SocketError.Success) { Log.Error($"accept error {e.SocketError}"); return; } TChannel channel = new TChannel(e.AcceptSocket, this); this.idChannels[channel.Id] = channel; try { this.OnAccept(channel); } catch (Exception exception) { Log.Error(exception); } if (this.acceptor == null) { return; } this.AcceptAsync(); }
public override AChannel GetChannel(long id) { TChannel channel = null; this.idChannels.TryGetValue(id, out channel); return(channel); }
private void OnAcceptComplete(object sender, SocketAsyncEventArgs o) { SocketAsyncEventArgs e = o; UserTokenInfo userTokenInfo = (UserTokenInfo)e.UserToken; if (userTokenInfo.InstanceId != this.InstanceId) { return; } if (e.SocketError != SocketError.Success) { Log.Error($"accept error {e.SocketError}"); return; } TChannel channel = new TChannel(e.AcceptSocket, this); this.idChannels[channel.Id] = channel; try { this.OnAccept(channel); } catch (Exception exception) { Log.Error(exception); } if (userTokenInfo.InstanceId != this.InstanceId) { return; } this.AcceptAsync(); }
/// <summary> /// 连接服务器成功回调 /// </summary> /// <param name="o"></param> private void OnAcceptComplete(object o) { if (this.acceptor == null) { return; } SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; if (e.SocketError != SocketError.Success) { Log.Error($"accept error {e.SocketError}"); return; } TChannel channel = new TChannel(e.AcceptSocket, this); //根据远程端的Socket 得到和它的通讯信道TChannel this.idChannels[channel.Id] = channel; //注册到字典 try { this.OnAccept(channel); //把这个远程端Socket(这里就是服务器Socket)抛到上层 } catch (Exception exception) { Log.Error(exception); } if (this.acceptor == null) { return; } this.AcceptAsync(); //开始下一个远程端的监听 }
public override AChannel ConnectChannel(IPEndPoint ipEndPoint) { TcpClient tcpClient = new TcpClient(); TChannel channel = new TChannel(tcpClient, ipEndPoint, this); this.idChannels[channel.Id] = channel; return(channel); }
public override async Task <AChannel> AcceptChannel() { if (this.acceptor == null) { throw new Exception("service construct must use host and port param"); } TcpClient tcpClient = await this.acceptor.AcceptTcpClientAsync(); TChannel channel = new TChannel(tcpClient, this); this.idChannels[channel.Id] = channel; return(channel); }
public override void Dispose() { if (this.acceptor == null) { return; } foreach (long id in this.idChannels.Keys.ToArray()) { TChannel channel = this.idChannels[id]; channel.Dispose(); } this.acceptor.Stop(); this.acceptor = null; }
public override void Dispose() { if (this.IsDisposed) { return; } base.Dispose(); foreach (long id in this.idChannels.Keys.ToArray()) { TChannel channel = this.idChannels[id]; channel.Dispose(); } this.acceptor?.Close(); this.acceptor = null; this.innArgs.Dispose(); }
public override void Dispose() { bool IsDisposeLocal = this.IsDispose; base.Dispose(); this.IsDispose = true; if (IsDisposeLocal) { return; } foreach (long id in this.idChannels.Keys.ToArray()) { TChannel channel = this.idChannels[id]; channel.Dispose(); } this.acceptor?.Close(); this.acceptor = null; this.innArgs.Dispose(); }
private void OnAcceptComplete(object o) { if (this.acceptor == null) { return; } SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; if (e.SocketError != SocketError.Success) { Log.Error($"accept error {e.SocketError}"); //进入下一次的接受连接 this.AcceptAsync(); return; } //构建一个通道TChannel,然后将连接的socket传递进去 TChannel channel = new TChannel(e.AcceptSocket, this); //缓存该通道 this.idChannels[channel.Id] = channel; try { //调用构造函数缓存的回调 并且将channel通道传递进去 this.OnAccept(channel); } catch (Exception exception) { Log.Error(exception); } if (this.acceptor == null) { return; } //进入下一次的接受连接 this.AcceptAsync(); }