コード例 #1
0
 public static async Task StartAsync(IPAddress ipAddress, int port, TcpIpClientOptions tcpIpClientOptions)
 {
     if (tcpIpClientOptions == null)
     {
         tcpIpClientOptions = new TcpIpClientOptions();
     }
     using (TextTcpIpClient tcpIpClient = new TextTcpIpClient(tcpIpClientOptions.Identifier, tcpIpClientOptions.BufferLength,
                                                              tcpIpClientOptions.EndOfLine, tcpIpClientOptions.SynchronizationContext, tcpIpClientOptions.GetTcpClient,
                                                              tcpIpClientOptions.GetTcpReceiver, tcpIpClientOptions.OnDataItemReceived, tcpIpClientOptions.OnDataReceived))
     {
         if (tcpIpClientOptions.OnConnecting != null)
         {
             tcpIpClient.Connecting += (o, e) => tcpIpClientOptions.OnConnecting(o, e.TcpClient);
         }
         if (tcpIpClientOptions.OnConnected != null)
         {
             tcpIpClient.Connected += (o, e) => tcpIpClientOptions.OnConnected(o, e.TcpClient);
         }
         await tcpIpClient.ConnectAsync(ipAddress, port).ConfigureAwait(false);
     }
 }
コード例 #2
0
 public static async Task StartAsync(IPEndPoint ipEndPoint, TcpIpClientOptions tcpIpClientOptions)
 {
     ThrowIf.ArgumentIsNull(ipEndPoint, nameof(ipEndPoint));
     await StartAsync(ipEndPoint.Address, ipEndPoint.Port, tcpIpClientOptions).ConfigureAwait(false);
 }