Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void canCall()
- {
- try
- {
- UnityEngine.Debug.Log("Start check can call");
- IPAddress ipAddress = default(IPAddress);
- EndPoint endPoint = default(EndPoint);
- try
- {
- ipAddress = IPAddress.Parse(Ip);
- endPoint = new IPEndPoint(ipAddress, 5551);
- }
- catch (System.Threading.ThreadAbortException abort)
- {
- UnityEngine.Debug.Log("Exiting can call thread");
- if (canCallCallback != null)
- {
- canCallCallback(false);
- }
- return;
- }
- catch (System.Exception ex)
- {
- UnityEngine.Debug.LogException(ex);
- if(canCallCallback != null)
- {
- canCallCallback(false);
- }
- return;
- }
- using (Socket socket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
- {
- UnityEngine.Debug.Log("Executing command");
- try
- {
- socket.Connect(endPoint);
- } catch (Exception ex)
- {
- UnityEngine.Debug.Log("Socket connect error " + ex);
- if (canCallCallback != null)
- {
- canCallCallback(false);
- }
- }
- socket.Disconnect(false);
- if (canCallCallback != null)
- {
- canCallCallback(true);
- }
- }
- }
- catch (System.Threading.ThreadAbortException abort)
- {
- UnityEngine.Debug.Log("Exiting can call thread");
- if (canCallCallback != null)
- {
- canCallCallback(false);
- }
- return;
- }
- catch (System.Exception ex)
- {
- UnityEngine.Debug.LogError("Error executing command in can call thread");
- if (canCallCallback != null)
- {
- canCallCallback(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement