A
A
AlexSer2018-05-05 12:16:24
linux
AlexSer, 2018-05-05 12:16:24

How to organize data loading via TCP?

Hello! Can you suggest what I'm doing wrong.
There is a device that transmits data on the com port! These data must be received and transferred to the WEB server for further processing and loading into the database.
I receive data and send it to the server, but something goes wrong on the server side. Opened port 10000
on the web server (UBUNTU) with the command

<b> iptables -A INPUT -i eth0 -p tcp —dport 10000 -j ACCEPT</b>

Disabled the firewall on the server.
On one of the pages of the Yii2 application I inserted the code
$address = '192.168.1.180';
  $port = 10 000;
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

  socket_connect($socket, $address, $port);
  socket_write($socket, "GET / HTTP/1.0\r\n\r\n");

  $result = "";

  while($read = socket_read($socket, 1024))
  {
      $result .= $read;
  }
  socket_close($socket);

  echo "Полученный результат:  $result\r\n";

But an error comes up
PHP Warning – yii\base\ErrorException
socket_connect(): unable to connect [111]: Connection refused

If I put port 80. there are no errors.
Can you explain, those who dealt with such problems, how to organize it correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Fedoseev, 2018-05-05
@martin74ua

Look at the socket_listen function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question