示例#1
0
 public static async Task StartAsync(IPAddress ipAddress, int port, TcpIpServerOptions tcpIpServerOptions)
 {
     if (tcpIpServerOptions == null)
     {
         tcpIpServerOptions = new TcpIpServerOptions();
     }
     using (TextTcpIpServer tcpIpServer = new TextTcpIpServer(tcpIpServerOptions.Identifier, tcpIpServerOptions.BufferLength,
                                                              tcpIpServerOptions.EndOfLine, tcpIpServerOptions.SynchronizationContext, tcpIpServerOptions.GetTcpListener,
                                                              tcpIpServerOptions.GetTcpReceiver, tcpIpServerOptions.OnDataItemReceived, tcpIpServerOptions.OnDataReceived))
     {
         if (tcpIpServerOptions.OnListeningStarting != null)
         {
             tcpIpServer.ListeningStarting += (o, e) => tcpIpServerOptions.OnListeningStarting(o, e.TcpListener);
         }
         if (tcpIpServerOptions.OnListeningStarted != null)
         {
             tcpIpServer.ListeningStarted += (o, e) => tcpIpServerOptions.OnListeningStarted(o, e.TcpListener);
         }
         if (tcpIpServerOptions.OnClientAdded != null)
         {
             tcpIpServer.ClientAdded += (o, e) => tcpIpServerOptions.OnClientAdded(o, e.TcpClientKey, e.TcpClient);
         }
         await tcpIpServer.StartListeningAsync(ipAddress, port).ConfigureAwait(false);
     }
 }
示例#2
0
 public static async Task StartAsync(IPEndPoint ipEndPoint, TcpIpServerOptions tcpIpServerOptions)
 {
     ThrowIf.ArgumentIsNull(ipEndPoint, nameof(ipEndPoint));
     await StartAsync(ipEndPoint.Address, ipEndPoint.Port, tcpIpServerOptions).ConfigureAwait(false);
 }