Created
March 18, 2016 18:02
-
-
Save viebig/2a4229f02b1eaaccccba to your computer and use it in GitHub Desktop.
Simple HTTP echo server (Generic TCP)
This file contains 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 | |
// | |
// By: Spicer Matthews <[email protected]> | |
// Company: Cloudmanic Labs, LLC | |
// Date: 5/19/2011 | |
// Description: This is an echo server. It will read any messages sent in and then echo them back out. | |
// | |
$hostname = "127.0.0.1"; | |
$portno = "7834"; | |
ob_implicit_flush(); | |
set_time_limit(0); | |
$sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("Socket create | |
error\n"); | |
socket_bind($sock, $hostname, $portno) or die("Socket bind error\n"); | |
socket_listen($sock, 3) or die("Could not set up socket listener\n"); | |
while(1) | |
{ | |
echo "socket connection started\n"; | |
$accept = socket_accept($sock) or die("Could not accept incoming | |
connection\n"); | |
while($recv = socket_read($accept, 24000)) | |
{ | |
echo 'Client Said: ' . $recv; | |
$msg = 'Server Said: ' . $recv . "\r\n"; | |
socket_write($accept, $msg, strlen($msg)) or die("Could not write output\n"); | |
} | |
socket_close($accept); | |
echo "socket connection done\n"; | |
} | |
socket_close($sock); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment