Advertisement
Alior

Untitled

Oct 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1.     void canCall()
  2.     {
  3.         try
  4.         {
  5.  
  6.             UnityEngine.Debug.Log("Start check can call");
  7.             IPAddress ipAddress = default(IPAddress);
  8.             EndPoint endPoint = default(EndPoint);
  9.  
  10.             try
  11.             {
  12.                 ipAddress = IPAddress.Parse(Ip);
  13.                 endPoint = new IPEndPoint(ipAddress, 5551);
  14.             }
  15.             catch (System.Threading.ThreadAbortException abort)
  16.             {
  17.                 UnityEngine.Debug.Log("Exiting can call thread");
  18.                 if (canCallCallback != null)
  19.                 {
  20.                     canCallCallback(false);
  21.                 }
  22.                 return;
  23.             }
  24.             catch (System.Exception ex)
  25.             {
  26.                 UnityEngine.Debug.LogException(ex);
  27.                 if(canCallCallback != null)
  28.                 {
  29.                     canCallCallback(false);
  30.                 }
  31.                 return;
  32.             }
  33.            
  34.             using (Socket socket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
  35.             {
  36.                 UnityEngine.Debug.Log("Executing command");
  37.  
  38.                 try
  39.                 {
  40.                     socket.Connect(endPoint);
  41.                 } catch (Exception ex)
  42.                 {
  43.                     UnityEngine.Debug.Log("Socket connect error " + ex);
  44.  
  45.                     if (canCallCallback != null)
  46.                     {
  47.                         canCallCallback(false);
  48.                     }
  49.                 }
  50.  
  51.                 socket.Disconnect(false);
  52.  
  53.                 if (canCallCallback != null)
  54.                 {
  55.                     canCallCallback(true);
  56.                 }
  57.             }
  58.         }
  59.         catch (System.Threading.ThreadAbortException abort)
  60.         {
  61.             UnityEngine.Debug.Log("Exiting can call thread");
  62.             if (canCallCallback != null)
  63.             {
  64.                 canCallCallback(false);
  65.             }
  66.             return;
  67.         }
  68.         catch (System.Exception ex)
  69.         {
  70.             UnityEngine.Debug.LogError("Error executing command in can call thread");
  71.             if (canCallCallback != null)
  72.             {
  73.                 canCallCallback(false);
  74.             }
  75.         }
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement