У меня есть приведенный ниже примерный поток данных, который должен быть передан в систему через программирование сокетов. Этот поток генерируется из db. Каждый 243 char я получаю новый поток.Передача данных в систему через сокет с использованием PHP
> 0243P254NIP40524KCK0240000000104844200001
> 00000064005736540000000985714052400000000000010000000000000000BIR01082013KCK*IBKL0KCK01*130718i28535983*lazy
> frog
> KCK0240000000104844200001KCK0240000000104844200001KCK02400000001048442
Я попытался под кодом, но как я прочитал поток и наметил ответ на ввод.
каждый раз, когда я получаю сообщение ниже от server.php «Не удалось прочитать вход» из client.php «не удалось отправить данные на сервер»
пожалуйста скажите мне, как я могу сделать sever.php чтения данные и client.php отправить данные
server.php
<?php
$host = "217.16.1.12";
$port = 10001;
$message = "Hello Client";
set_time_limit(0);
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
// put server into passive state and listen for connections
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
// accept incoming connections
$com = socket_accept($socket) or die("Could not accept incoming connection\n");
// read client input
$input = socket_read($com, 1024000) or die("Could not read input\n");
// clean up input string
$input = trim($input);
echo "Client says: ".$input;
socket_write($com, $message , strlen ($message)) or die("Could not write output\n");
// close sockets
socket_close($com);
socket_close($socket);
?>
client.php
<?php
include ("db/Config.php");
$host = "217.16.1.12";
$port = 10001;
$data = mysql_query("select isbn from klrans where isbn is not NULL and isbn <> '' limit 5");
while($info = mysql_fetch_array($data))
{
$ifsc= $info['isbn'];
$msg .= "<td align='center'>".$isbn. "</td> ";
}
$message = $msg;
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// connect to server
$result = socket_connect($socket, $host, $port) or die ("Could not connect to server\n");
// send string to server
socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");
// get server response
$result = socket_read ($socket, 1024000) or die("Could not read server response\n");
echo "Server says :".$result;
// close socket
socket_close($socket);
?>