Warning: Unsuccessful read: A timeout occurred before the Terminator was reached.

5 ビュー (過去 30 日間)
Marc
Marc 2013 年 12 月 16 日
コメント済み: Rashi Mehrotra 2021 年 8 月 11 日
I'm trying to send data back and forth between a php socket client and a matlab tcpip server. I've done a proof of concept with the php client talking to a php socket server and everything works. I've also been able to make the matlab server send text back to the php client. However, I can't read the message from the php client in Matlab.
Here's the Matlab server code:
%%matlab tcpip server
c1 = tcpip('127.0.0.1', 30000, 'NetworkRole', 'server');
fopen(c1);
disp('waiting for data from client...');
received=false;
while received==false
try
A=fscanf(c1);
catch err
disp('error receiving from client');
end
try
%fprintf(c1,'server written response');
fprintf(c1,A);
catch err
disp('error writing back');
end
received=true;
end
fclose(c1);
The php code is as follows:
<?php
// php socket client
$host = "127.0.0.1";
$port = 30000;
$message = "HelloServer\n ";
echo "Sending message To server :".$message . "<br />";
// 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");
echo "socket write completed<br />";
// get server response
$result = socket_read($socket, 1024, PHP_NORMAL_READ) or die("Could not read server response\n");
echo "<br />Reply From Server: ".$result;
// close socket
socket_close($socket);
?>
The place that is failing is "A=fscanf(c1);". I've tried it with various other params added but can't get it to receive data. Is there something I'm missing? How should this line and/or the format of the message be set to work? Thanks for any help you can offer.
  4 件のコメント
Rashi Mehrotra
Rashi Mehrotra 2021 年 8 月 11 日
I am facing the same problem with udp, Marc did you solve this and how?

サインインしてコメントする。

回答 (0 件)

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by