PHP Socket programming

Source: Internet
Author: User

The following code is used:
PHP code:
Copy codeThe Code is as follows:
<?
// Set some basic variables
$ Host = "192.168.1.99 ";
$ Port = 1234;
// Set the timeout value
Set_time_limit (0 );
// Create a Socket
$ Socket = socket_create (AF_INET, SOCK_STREAM, 0) or die ("cocould not create
Socket \ n ");
// Bind the Socket to the port
$ Result = socket_bind ($ socket, $ host, $ port) or die ("cocould not bind
Socket \ n ");
// Start listening Link
$ Result = socket_listen ($ socket, 3) or die ("cocould not set up socket
Listener \ n ");
// Accept incoming connections
// Another Socket for communication
$ Spawn = socket_accept ($ socket) or die ("cocould not accept incoming
Connection \ n ");
// Obtain client input
$ Input = socket_read ($ spawn, 1024) or die ("cocould not read input \ n ");
// Clear the input string
$ Input = trim ($ input );
// Process client input and return results
$ Output = strrev ($ input). "\ n ";
Socket_write ($ spawn, $ output, strlen ($ output) or die ("cocould not write
Output \ n ");
// Disable sockets
Socket_close ($ spawn );
Socket_close ($ socket );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.