PHP Socket Programming_PHP Tutorial

WBOY
Release: 2016-07-21 15:39:33
Original
819 people have browsed it

The following is the corresponding code:
PHP code:

Copy code The code is as follows:

// Set some basic variables
$host = "192.168.1.99";
$port = 1234;
// Set timeout
set_time_limit(0);
// Create a Socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create
socketn");
//Bind Socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to
socketn");
// Start listening to the link
$result = socket_listen($socket, 3) or die("Could not set up socket
listenern");
// accept incoming connections
// Another Socket to handle communication
$spawn = socket_accept($socket) or die("Could not accept incoming
connectionn ");
// Get input from the client
$input = socket_read($spawn, 1024) or die("Could not read inputn");
// Clear the input string
$input = trim($input);
//Process client input and return the result
$output = strrev($input) . "n";
socket_write($spawn, $output, strlen ($output )) or die("Could not write
outputn");
// Close sockets
socket_close($spawn);
socket_close($socket);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321583.htmlTechArticleThe following is the corresponding code: PHP code: Copy the code as follows: ? // Set some basic variables $host = "192.168.1.99"; $port = 1234; // Set the timeout set_time_limit(0); // Create...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template