Hi,
I am trying to open up a socket on an XAMP installation (Windows XP host) but keep receiving the following error:
And this is the code:
<?php
define("SOCK_PORT", 8080);
define("SQL_HOST", "127.0.0.1");
define("SQL_USER", "root");
define("SQL_PASS", "");
define("SQL_DBASE", "my_db");
// Add Data function, takes data in form gameid.playerid.score and stores it in MySQL table 'scores'
function add_data( $data )
{
global $mysql;
// Parse $data
list($gameid, $playerid, $score) = explode(".", $data);
// Construct SQL Query
$sql = "INSERT INTO scores(gameid, playerid, score) VALUES(${gameid}, ${playerid}, ${score})";
// Run SQL Query
mysql_query( $sql, $mysql ) or die(mysql_error());
}
// Open MySQL and Select Database
$mysql = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die(mysql_error());
mysql_select_db(SQL_DBASE, $mysql) or die(mysql_error());
// Open UDP Socket
$sock = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ) or die(socket_strerror(socket_last_error($sock)));
// Bind Socket to SOCK_PORT on '0.0.0.0'
socket_bind( $sock, '0.0.0.0', SOCK_PORT ) or die(socket_strerror(socket_last_error($sock)));
//socket_bind( $sock, '127.0.0.1', SOCK_PORT ) or die(socket_strerror(socket_last_error($sock)));
// Set Socket to Blocking
socket_set_block( $sock ) or die(socket_strerror(socket_last_error($sock)));
// Loop forever, waiting for connections
while(TRUE) {
// Get first 65536 bytes from Socket and store as $buf (also get $clientip and $clientport)
socket_recvfrom( $sock, $buf, 65535, 0, $clientip, $clientport ) or die(socket_strerror(socket_last_error($sock)));
// Run add_data function on the data recieved from socket
add_data( $buf );
}
// Never Should reach here, but if it is changed to shut down: Close the socket & mysql gracefully
socket_close( $sock );
mysql_close( $mysql );
?>
I figure using Port 8080 would be fine? I then I would enter the games score by passing it through the URL:
http://localhost/submitscore.php:8080
But when I try to load the page, I keep on getting the error at the top.
Could anyone provide a solution?