B
B
BloodVIRUS2017-08-02 13:12:32
PHP
BloodVIRUS, 2017-08-02 13:12:32

How to transfer data from the server to the program?

Hello. There was a need to transfer data from the site to the computer. I came up with the idea to write a simple software in Delphi, in which there will be a tcp server, and data will be sent from the site by a socket. But something goes wrong, or I'm doing something fundamentally wrong. In delphi, I throw the TcpServer component, specify the port 80, immediately make it Active: true, and in order to understand that the server received some data on the TcpServer1Accept event, I simply hang up showmessage ('hallo');
On the php side, I took an example from php.net

$fp = stream_socket_client("tcp://128.75.114.10:80", $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, "GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n");
    while (!feof($fp)) {
        echo fgets($fp, 1024);
    }
    fclose($fp);
}

But I got a connection error. Somewhere I found another example of working with sockets:
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    $msg = "Пинг !";
    $len = strlen($msg);

    socket_sendto($sock, $msg, $len, 0, '128.75.114.10', 80);
    socket_close($sock);

So is silence. PHP does not give errors, the application is silent.
Please tell me what am I doing wrong? The last time I coded on Delphi was 7 years ago, but on PHP I never had a chance to work with sockets ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2017-08-02
@zkelo

You can do without sockets. The site probably uses a database. You can write a program that will access this database and get the necessary data from there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question