1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
<?php
// set some variables
$host = "192.168.1.19";
$port = 4070;
// don't timeout!
set_time_limit(0);
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
// start listening for connections
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
while($input!="exitvertx")
{
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
$input = socket_read($spawn, 1024) or die("Could not read input\n");
$input = trim($input);
if(strlen($input)>0)
{
iF($input=="exitvertx")
{
break;
}
else
{
socket_write($spawn, $input, strlen ($input)) or die("Could not write input\n");
}
}
$output =$input . "\n";
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
}
socket_close($spawn);
socket_close($socket);
?> |
Partager