Connecting to a TCP/IP server via php script
php, tcp
Solution
Easily with php sockets:
<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fwrite($fp, "Your message");
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
To read more, go to http://php.net/manual/en/function.fsockopen.php
Problem
I need to implement a php script on my website that would do the following: - Connect to a remote server - Send packet to the server - Receive packet from the server Everything is already configurated on the server side to respond to packet requests, I only need to figure out how to use php to connect to TCP/IP server. Any ideas in which direction to look?