示例#1
0
 private async void NewClient(Socket socket, int millisecondsDelay)
 {
     try
     {
         socket.Connect(address);
         OnConnect?.Invoke(this, new EventArgs());
     }
     catch (Exception exception)
     {
         OnConnectException?.Invoke(this, new ExceptionEventArgs(socket, exception));
     }
     while (true)
     {
         try
         {
             socket.Send(messageBuffer);
             OnSend?.Invoke(this, new EventArgs());
         }
         catch (Exception exception)
         {
             OnSendException?.Invoke(this, new ExceptionEventArgs(socket, exception));
         }
         await Task.Delay(millisecondsDelay);
     }
 }
示例#2
0
 private void SendAsync(Socket client, byte[] messageBuffer, bool useExceptionList)
 {
     byte[] messageBytes = Buffer.AddSplitter(messageBuffer, 0);
     try
     {
         client.Send(messageBytes);
         OnServerSend?.Invoke(this, new EventArgs());
     }
     catch (Exception exception)
     {
         if (useExceptionList)
         {
             CheckException(exception);
         }
         else
         {
             OnSendException?.Invoke(this, new ExceptionEventArgs(client, exception));
         }
     }
 }