My situation:
- I have a program which send on a port (4448) a lot of data from some machines.
- I can retrieve that datas from a telnet connection.
telnet steps:
- launch as cmd as ADMIN
- write telnet and send
- write "open localhost 4448" and send
- write "GET xx,yy"
- after this i just read on screen info in live
xx and yy are numbers which identifies the machine
Now lets go on php side I have my index.php but when I execute socket bind it gives me back an error (reported under the code) and about the code, this come from: http://php.net/manual/en/sockets.examples.php and its the first example, i read and tried this solution also https://www.codeproject.com/Tips/418814/Socket-Programming-in-PHP which use 2 php files, in both cases i get the same error...
<?php
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
$address = 'localhost';
$port = 4448;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "
";
}
if (socket_bind($sock, $address, $port) === false) {
echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "
";
}
if (socket_listen($sock, 5) === false) {
echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "
";
}
do {
if (($msgsock = socket_accept($sock)) === false) {
echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "
";
break;
}
/* Send instructions. */
$msg = "GET xx,yy";
socket_write($msgsock, $msg, strlen($msg));
do {
if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "
";
break 2;
}
if (!$buf = trim($buf)) {
continue;
}
if ($buf == 'quit') {
break;
}
if ($buf == 'shutdown') {
socket_close($msgsock);
break 2;
}
$talkback = "PHP: You said '$buf'.
";
socket_write($msgsock, $talkback, strlen($talkback));
echo "$buf
";
} while (true);
socket_close($msgsock);
} while (true);
socket_close($sock);
?>
and this is the error i get:
Warning: socket_bind(): unable to bind address [10013]: An attempt was made to access a socket in a way forbidden by its access permissions
I have already looked for administrator privileges and I think its all right.
Extra info: I am working with PHP 7, my web server is Apache in Xampp package.