SocketExtensions.cs 396 B

12345678910111213141516
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Net.Sockets;
  4. using UnityEngine;
  5. public static class SocketExtensions
  6. {
  7. public static bool IsConnected(this Socket socket)
  8. {
  9. try
  10. {
  11. return !(socket.Poll(1, SelectMode.SelectRead) && socket.Available == 0);
  12. }
  13. catch (SocketException) { return false; }
  14. }
  15. }