Ejemplo n.º 1
0
        public StatusTransaction sendMessageTCPServer(string message, int limitLoop = 10)
        {
            try
            {
                Socket                m_socClient        = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                RemoteIPAddress       objRemoteIPAddress = new RemoteIPAddress();
                System.Net.IPEndPoint remoteEndPoint     = new System.Net.IPEndPoint(objRemoteIPAddress.GetObjectIPAddress(), GetPort());

                byte[] byData = System.Text.Encoding.ASCII.GetBytes(message);

                int loopSend = 0;
                do
                {
                    try
                    {
                        loopSend++;
                        m_socClient.Connect(remoteEndPoint);
                        if (m_socClient.Connected)
                        {
                            m_socClient.Send(byData);
                            return(StatusTransaction.True);
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        if (m_socClient.Connected)
                        {
                            m_socClient.Close();
                        }
                    }
                }while (loopSend < limitLoop);
                return(StatusTransaction.False);
            }
            catch (Exception ex)
            {
                Program.MessageError("ClsTCPClient", "sendMessageTCPServer", ex, false);
                return(StatusTransaction.Error);
            }
        }
Ejemplo n.º 2
0
        public void sendMessegeToUnitDisplay(string Messege)
        {
            Socket          m_socClient        = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            RemoteIPAddress objRemoteIPAddress = new RemoteIPAddress();

            System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(objRemoteIPAddress.GetObjectIPAddress(), GetPort());

sendNew:
            try
            {
                m_socClient.Connect(remoteEndPoint);
                byte[] byData = System.Text.Encoding.ASCII.GetBytes(Messege);
                m_socClient.Send(byData);
                m_socClient.Close();
            }
            catch
            {
                goto sendNew;
                //Program.MessageError("ClsTCPClient", "sendMessegeToUnitDisplay", ex.Message, false);
                //if (m_socClient.Connected == false) { return; };
            }
        }