PHP socket read data display related issues

Source: Internet
Author: User
PHP socket read Data display problem
Now the buffer can be printed out using PHP to connect to the socket, and the display on the webpage is as follows:

The received data is as follows:
Response Was:1
Response Was:1
Response Was:1
Response Was:1
Response Was:1
Response Was:1
Response Was:1

Now is to put this buffer into a text box, and has been refreshed, do not know how to achieve, please the great God help. Here is my Code!






if (Isset ($_post[' button ')) {
echo "received the data as follows:";
echo "
";
$port =$_post["T2"];
$host =$_post["T1"];
Set_time_limit (0);
$socket = Socket_create (Af_inet, Sock_stream, sol_tcp) or Die ("Could not create socket\n"); Create a socket
$connection = Socket_connect ($socket, $host, $port) or Die ("Could not connet server\n"); Connection
$connection = Socket_connect ($socket, "127.0.0.1", 7777) or Die ("Could not connet server\n"); Connection
Socket_write ($socket, "hello socket") or Die ("Write failed\n"); Data transfer sends a message to the server
Ob_end_flush ();
echo Str_pad ("", 256);

while ($buffer =socket_read ($socket, 1,php_normal_read)) {
echo "Response was:". $buffer. " \ n ";
echo "
";
Flush ();
}
Socket_close ($socket);

}
if (Isset ($_post[' button2 ')) {

Socket_close ($socket);
}
?>

Share to: more


------Solutions--------------------
Response was:

.
.
.
.
echo "";
  • 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.