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

2 views (last 30 days)
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 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!