Multiple communication of the socket client-php the socket client
Source: Internet
Author: User
KeywordsSocket client Socket JS PHP
Socket Client socketjsphp
Want to use PHP to do a socket client, you can implement a connection, and then send a message to the server multiple times. The concrete idea is this: To make a page, this page has a button and the Message bar, click the button to send the content of the message bar to the server, then click again send, and do not need to reconnect, but the page opened with the server connection. How is this going to come true? Please Daniel to help, the younger sister thanked first. Enclose the code for the Socket class.
/** define IP, and port */
Define (' Php_socket_port ', ' 6000 '); Define (' Php_socket_host ', ' 127.0.0.1 '); Define (' Php_socket_start ', '); Define (' Php_socket_end ', '); Socket class Class socket{ var $socket; Socket handle var $sendflag = ">>>"; var $recvflag = "<<<"; var $response; var $debug = 1; function socket ($hostname, $port) { $address = gethostbyname ($hostname); $this->socket = socket_create (AF_INET,SOCK_STREAM,SOL_TCP); $result = Socket_connect ($this->socket, $address, $port); if ($this->debug = = 1) { if ($result < 0) { $result = "Socket_connect () Failed.\nreason: ($result)". Socket_strerror ($result). " "; } else{ $result = "Connect OK. "; } }
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.