1. Go to this page and download the library: Download clue/socket-raw library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
clue / socket-raw example snippets
$factory = new \Socket\Raw\Factory();
$socket = $factory->createClient('www.google.com:80');
echo 'Connected to ' . $socket->getPeerName() . PHP_EOL;
// send simple HTTP request to remote side
$socket->write("GET / HTTP/1.1\r\n\Host: www.google.com\r\n\r\n");
// receive and dump HTTP response
var_dump($socket->read(8192));
$socket->close();
$factory = new \Socket\Raw\Factory();
// establish a TCP/IP stream connection socket to www.google.com on port 80
$socket = $factory->createClient('tcp://www.google.com:80');
// same as above, as scheme defaults to TCP
$socket = $factory->createClient('www.google.com:80');
// same as above, but wait no longer than 2.5s for connection
$socket = $factory->createClient('www.google.com:80', 2.5);
// create connectionless UDP/IP datagram socket connected to google's DNS
$socket = $factory->createClient('udp://8.8.8.8:53');
// establish TCP/IPv6 stream connection socket to localhost on port 1337
$socket = $factory->createClient('tcp://[::1]:1337');
// connect to local Unix stream socket path
$socket = $factory->createClient('unix:///tmp/daemon.sock');
// create Unix datagram socket
$socket = $factory->createClient('udg:///tmp/udg.socket');
// create a raw low-level ICMP socket (
// create a TCP/IP stream connection socket server on port 1337
$socket = $factory->createServer('tcp://localhost:1337');
// create a UDP/IPv6 datagram socket server on port 1337
$socket = $factory->createServer('udp://[::1]:1337');