Receive real-time count from a program

Asked

Viewed 50 times

-2

It is possible to make a program. exe, which had a 60-second timer, and every second it passed would send information to a php page and this php page showed the change of seconds in real time depending on the program?

If possible, how could I do this?

Thank you.

  • Yes, but take into account the time delay in communication (internet), it may be that this "real time", is not so real ... heheheh. Depending on the language or tool you use to generate ". exe" it is even quite simple to send a request to a PHP server. However, in PHP, the simplest way (maybe the only way, I don’t know...) is to put this value in the database, and make the other "connections" constantly check for this change. Which would probably cause more delay.

  • 1

    doubt is about how to make such a program . exe or is it about php?

  • That’s basically what usel5978 is saying.

  • It’s about PHP and exe

1 answer

1

It is possible.

The following C# code can be compiled for a file .exe, and does: forever (1), wait sixty seconds (2), make a request on a PHP page (3) and take what the page print to process (4).

    public static void Main( string[] args )
    {
        int dados = 0;
        while ( true ) // 1
        {
            System.Threading.Thread.Sleep( TimeSpan.FromSeconds( 60 ) ); // 2
            dados++;
            using ( var client = new System.Net.WebClient() )
            {
                var retorno = client.DownloadString( "http://servidor.url/pagina.php?dado=" + dados ); // 3
                Console.WriteLine( retorno ); // 4
            }
        }
    }

You need to download a C# programming IDE or its equivalent in another language.

It is also possible to do an . exe of a PHP, but it is not such a common solution.

  • This C#code, it is possible to send the value every second you pass to this.php page via get?

  • Yes. Just change the TimeSpan.FromSeconds( 60 ) for TimeSpan.FromSeconds( 1 ). You’d have to tweak the code to be exactly one second between calls, but that would involve thread control, which seems to be a little beyond your original question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.