Skip to content

Instantly share code, notes, and snippets.

@countingpine
Forked from miguelmota/nc.php
Created June 22, 2023 16:46
Show Gist options
  • Save countingpine/014f09ac545df6b04d04d19397eff420 to your computer and use it in GitHub Desktop.
Save countingpine/014f09ac545df6b04d04d19397eff420 to your computer and use it in GitHub Desktop.
PHP send message to socket server (netcat)
<?php
$payload = 'hello world';
$stream = stream_socket_client("tcp://127.0.0.1:5555", $errno, $errstr);
if (!$stream) {
echo "{$errno}: {$errstr}\n";
die();
}
fwrite($stream, $payload);
stream_socket_shutdown($stream, STREAM_SHUT_WR);
$contents = stream_get_contents($stream);
fclose($stream);
echo $contents;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment