Read Socket in PHP, receive only Trash

时间:2018-08-22 13:59:36

标签: php sockets

i try to read gps data from my Teltonika router. I can receive data, but that are only trash for my eyes. So i cant parse that. That are my received data: (the red is my IMEI Number...) enter image description here

And that is my PHP:

<?php
require_once 'FMXXXX_Parser/Parser.class.php';

if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0))) {
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    die("Couldn't create socket: [$errorcode] $errormsg \n"); }

echo "Socket created \n";

if( !socket_bind($sock, '10.81.0.1' , 62250) ) {
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    die("Could not bind socket : [$errorcode] $errormsg \n"); }

echo "Socket bind OK \n";
$remote_ip = '10.81.0.1';
$remote_port = 62250;
while(1) {
    echo "Waiting for data ... \n";
    $r = socket_recvfrom($sock, $buf, 4096, 0, $remote_ip, $remote_port);
    echo "$remote_ip : $remote_port -- " . $buf;
    die;
}
socket_close($sock);

Have somebody an idea?

0 个答案:

没有答案