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); } }
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)); } } }