将php数组发送到套接字

时间:2019-06-20 14:53:47

标签: php laravel sockets websocket phpwebsocket

如何将php数组发送到套接字服务器? 我有一个webservice,我想将一个php数组发送到套接字webservices。 我该怎么办?

我已经尝试过了:

    $host = "170.51.249.101";
    $port = 8080;
    // No Timeout 
    set_time_limit(0);
    // Create a Data to send
    $data = "";
    $data .= "ID_PRESTADOR: ".$service_id."\n";
    $data .= "ID_TERMINAL: ".$atm_id."\n";
    $data .= "NRO_TRANSACCION: 123456\n";
    // Create socket
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
    // Connect to the server
    $result = socket_connect($socket, $host, $port) or die("Could not connect toserver\n");
    // Write to server socket
    socket_write($socket, $data, strlen($data)) or die("Could not send data to server\n");
    // Read the response from the server
    $result = socket_read ($socket, 1024) or die("Could not read server response\n");
    echo "Reply From Server  :".$result;
    // Close the socket
    socket_close($socket);
    die;

0 个答案:

没有答案