Created
January 29, 2019 07:04
-
-
Save miguelmota/a00107c8753fb14cd19c326cbb0e5ae6 to your computer and use it in GitHub Desktop.
PHP send message to socket server (netcat)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nc -l 5555 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment