开发者

how to send data to php server without having to keep reconnect?

开发者 https://www.devze.com 2023-03-23 11:21 出处:网络
I have a php socket server listening for connections. I am trying to pass score from php client to the server and the server will tabulate the results.

I have a php socket server listening for connections.

I am trying to pass score from php client to the server and the server will tabulate the results.

So far i am trying to pass it in this way: "http://localhost/gameClient.php?score=8"

How do i change the score frequently, without having to keep connecting to the server again and again?

Below is my client codes..

<?php 
//parameters to connect to server
$ip = "127.0.0.1";
$port = "8888";
$data = $_GET['score'];
$output = "";

// Create a TCP Stream Socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

// Connect to the server.
$result = socket_connect($socket, $ip, $port);

/开发者_开发技巧/ Write to socket!
socket_write($socket, $data, strlen($data));

// Read from server
do 
{
  $line =@socket_read($socket,2048);
  echo $line. "\n";
} 
while ($data != "0");

// Close and return.
socket_close($socket);
?>


i think comet will solve your problem!take a look at this : comet


You may try using a Java applet or a flash program to create a socket connection to your server. Than these applications will update the website as necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消