public Connect ( |
||
remoteEp | ||
return | void |
public void Connect(IPEndPoint remoteEp)
{
if (_state != TcpState.Closed)
{
throw new Exception("Closed Only");
}
_state = TcpState.Connecting;
_localEndPoint = null;
_remoteEndPoint = remoteEp;
_client = new TcpClient();
_client.BeginConnect(remoteEp.Address, remoteEp.Port, ConnectCallback, null);
}
public override Task<bool> ConnectAsync() { if (State != ChannelStateType.Closed) throw new InvalidOperationException("Should be closed to connect."); var tcs = _connectTcs = TaskFactory.Create<bool>(); _logger?.Info("Connect."); SetState(ChannelStateType.Connecting); var connection = new TcpConnection(_packetSerializer, _logger); _tcpConnection = connection; _tcpConnection.Connected += OnConnect; _tcpConnection.Received += OnReceive; _tcpConnection.Closed += OnClose; _tcpConnection.Connect(_remoteEndPoint); return tcs.Task; }