Beispiel #1
0
        private bool SendDTO(ResultDTO dto)
        {
            if (m_LostConnection)
            {
                return(false);
            }
#if UTT_SOCKETS_SUPPORTED
            try
            {
                using (var tcpClient = new TcpClient())
                {
                    var result  = tcpClient.BeginConnect(m_Ip, m_Port, null, null);
                    var success = result.AsyncWaitHandle.WaitOne(m_ConnectionTimeout);
                    if (!success)
                    {
                        return(false);
                    }
                    try
                    {
                        tcpClient.EndConnect(result);
                    }
                    catch (SocketException)
                    {
                        m_LostConnection = true;
                        return(false);
                    }

                    var bf = new DTOFormatter();
                    bf.Serialize(tcpClient.GetStream(), dto);
                    tcpClient.GetStream().Close();
                    tcpClient.Close();
                    Debug.Log("Sent " + dto.messageType);
                }
            }
            catch (SocketException e)
            {
                Debug.LogException(e);
                m_LostConnection = true;
                return(false);
            }
#endif  // if UTT_SOCKETS_SUPPORTED
            return(true);
        }
        private bool SendDTO(ResultDTO dto)
        {
            if (m_LostConnection) return false;
#if UTT_SOCKETS_SUPPORTED 
            try
            {
                using (var tcpClient = new TcpClient())
                {
                    var result = tcpClient.BeginConnect(m_Ip, m_Port, null, null);
                    var success = result.AsyncWaitHandle.WaitOne(m_ConnectionTimeout);
                    if (!success)
                    {
                        return false;
                    }
                    try
                    {
                        tcpClient.EndConnect(result);
                    }
                    catch (SocketException)
                    {
                        m_LostConnection = true;
                        return false;
                    }

                    var bf = new DTOFormatter();
                    bf.Serialize(tcpClient.GetStream(), dto);
                    tcpClient.GetStream().Close();
                    tcpClient.Close();
                    Debug.Log("Sent " + dto.messageType);
                }
            }
            catch (SocketException e)
            {
                Debug.LogException(e);
                m_LostConnection = true;
                return false;
            }
#endif  // if UTT_SOCKETS_SUPPORTED
            return true;
        }
 private bool SendDTO(ResultDTO dto)
 {
     if (m_LostConnection)
     {
         return(false);
     }
     try
     {
         using (TcpClient tcpClient = new TcpClient())
         {
             IAsyncResult asyncResult = tcpClient.BeginConnect(m_Ip, m_Port, null, null);
             if (!asyncResult.AsyncWaitHandle.WaitOne(m_ConnectionTimeout))
             {
                 return(false);
             }
             try
             {
                 tcpClient.EndConnect(asyncResult);
             }
             catch (SocketException)
             {
                 m_LostConnection = true;
                 return(false);
             }
             DTOFormatter dTOFormatter = new DTOFormatter();
             dTOFormatter.Serialize(tcpClient.GetStream(), dto);
             tcpClient.GetStream().Close();
             tcpClient.Close();
             Debug.Log("Sent " + dto.messageType);
         }
     }
     catch (SocketException exception)
     {
         Debug.LogException(exception);
         m_LostConnection = true;
         return(false);
     }
     return(true);
 }