Bueno estoy haciendo una pequeña aplicacion flash y hay intervienen unos archivos php, pero cuando enchunfo el server, me salta este error.
Fatal Error: Call to undifined function: socket_create<> in C:/Miserver/socket.php on line 165
La linea axacta es esto
$listenfd = socket_create(AF_INET, SOCK_STREAM, 0);Y si alguien quiere ver todo el archivo socket.php
<?
// to set the connection key
$keyencryption = "iamgoodseehowyoudecrypt";
//setting this to 0 lets scriphang around for ever
set_time_limit(0);
// defaults...
define('MAXLINE', 4096); // how much to read from a socket at a time
define('LISTENQ', 500); // listening queue
define('PORT', 10026); // the default port to run on
define('FD_SETSIZE', 500); // file descriptor set size (max number of concurrent clients)...
/* **********************************************
get usernames
********************************************** */
function getUsernames($r) {
global $ul;
//variable to hold usernamelist
$t = 'userlist';
for ($i = 0; $i < FD_SETSIZE; $i++)
{
//if is array and same room
if(is_array($ul[$i]) && $ul[$i]['room'] == $r)
$t .= '#'.$ul[$i][name].':'.$ul[$i][id];
}
return $t;
unset($t);
}
/* **********************************************
get rooms
********************************************** */
function getRooms(){
global $ul;
$t = 'roomlist';
//variable to hold roomlist
$r = array();
//array to check if room is in our list
$u = array();
//array to hold number of users in room
for ($i = 0; $i < FD_SETSIZE; $i++){
//if we have a client in allusers array
if(is_array($ul[$i])){
//if current room is not in "room array", we add it and clients in room are = 1
if (!in_array($ul[$i]['room'],$r)){
$r[] = $ul[$i]['room'];
$u[$ul[$i]['room']] = 1;
} else {
//new client in room found, increase
$u[$ul[$i]['room']]++;
}
}
}
// import and run the room list
include "roomlist.php";
//make the return string
foreach ($r as $ro){
$t .= '#'.$ro.'('.$u[$ro].')';
}
return $t;
}
/* **********************************************
join room (user, room, oldroom)
********************************************** */
function joinRoom($u, $r, $or, $myid, $param) {
global $ul, $i, $client;
$ul[$i]['room'] = $r;
//save room name before deleting the user
$n1 = getUsernames($r);
//users in current room
$n2 = getUsernames($or);
//users in old room
$ro = getRooms();
//get all rooms
//update users from rooms
for ($k = 0; $k < FD_SETSIZE; $k++)
{
if ($client[$k] != null) {
//if same room
if ($ul[$k]['room'] == $r){
socket_write($client[$k], 'enter#'.$u.'#'.$myid."#".$param.chr(0));
socket_write($client[$k], $n1.chr(0));
//if old room
} else if ($ul[$k]['room'] == $or){
socket_write($client[$k], 'leaveR#'.$u.'#'.$myid."#".$param.chr(0));
socket_write($client[$k], $n2.chr(0));
}
//update all users roomlist
socket_write($client[$k], $ro.chr(0));
}
}
}
/* **********************************************
for kill the server
********************************************** */
function killDaemon()
{
global $listenfd, $client,$rooms;
$msg = 'msg#server#Daemon going down!<br>';
for ($i = 0; $i < FD_SETSIZE; $i++)
{
if ($client[$i] != null){
socket_write($client[$i], $msg, strlen($msg));
socket_close($client[$i]);
}
}
print 'Shutting down the daemon<br>';
socket_close($listenfd);
exit;
}
/* **********************************************
whenever a client disconnects...
********************************************** */
function closeClient() {
global $client, $remote_host, $remote_port, $ul, $i;
socket_close($client[$i]);
//close & unset socket
$client[$i] = null;
unset($remote_host[$i]);
$oldroom = $ul[$i]['room'];
//save room name before unsetting user
$oldname = $ul[$i]['name'];
//save username before unsetting user
unset($ul[$i]);
$users = getUsernames($oldroom);
//get usernames in old room
$rooms = getRooms();
//get rooms
//check to see if anyone is still attached, this will shutdown the
//remove down from here if you want to remove this option server, remove if unwanted
$someoneconnected = false;
for ($k = 0; $k <= FD_SETSIZE; $k++){
if($client[$k] != null){
$someoneconnected = true;
//if someone is in old room
if ($ul[$k]['room'] == $oldroom){
socket_write($client[$k], 'leave#'.$oldname.chr(0));
socket_write($client[$k], $users.chr(0));
socket_write($client[$k], $rooms.chr(0));
//update all users rooms
} else {
socket_write($client[$k], $rooms.chr(0));
}
}
}
if($someoneconnected == false){
//killDaemon();
}
//stop removing here, for the auto shutdown feature
//search in roomname array and remove if nouonethere
}
// set up the file descriptors and sockets...
// $listenfd only listens for a connection, it doesn't handle anything
// but initial connections, after which the $client array takes over...
$listenfd = socket_create(AF_INET, SOCK_STREAM, 0);
if ($listenfd) {
print 'Listening on port '.PORT.'<br>';
} else {
die('AIEE -- socket died!<br>');
}
//set servers ip here, leave if using a local host
//socket_setopt($listenfd, SOL_SOCKET, SO_REUSEADDR, 1); - old
if (!@socket_setopt($listenfd, SOL_SOCKET, SO_REUSEADDR, 0)) {
echo 'socket_setopt() failed: reason: '.socket_strerror(socket_last_error($listenfd));
exit;
}
if (!socket_bind($listenfd, '0.0.0.0', PORT)){
socket_close($listenfd);
die("AIEE -- Couldn't bind!");
}
socket_listen($listenfd, LISTENQ);
// set up our clients. After listenfd receives a connection,
// the connection is handed off to a $client[]. $maxi is the
// set to the highest client being used, which is somewhat
// unnecessary, but it saves us from checking each and every client
// if only, say, the first two are being used.
//allow spaces for extra users, that will be automatically closed
for ($i = 0; $i < LISTENQ; $i++) {
$client[$i] = null;
}
// the main loop.
while(1){
$rfds[0] = $listenfd;
{
for ($i = 0; $i <= FD_SETSIZE; $i++)
if ($client[$i] != null)
$rfds[$i + 1] = $client[$i];
}
// block indefinitely until we receive a connection...
$nready = socket_select($rfds, $null, $null, null);
// if we have a new connection, stick it in the $client array,
if (in_array($listenfd, $rfds)) {
for ($i = 0; $i <= FD_SETSIZE; $i++){ //pick up the new spot
if ($client[$i] == null){
$client[$i] = socket_accept($listenfd);
socket_setopt($client[$i], SOL_SOCKET, SO_REUSEADDR, 0);
socket_getpeername($client[$i], $remote_host[$i], $remote_port[$i]);
// continue the server if connection allowed else allow next step
if ($i < FD_SETSIZE){
break;
}
}
if ($i >= FD_SETSIZE){
//trigger_error("too many clients", E_USER_ERROR);
//exit;
//or close the new socket,
closeClient();
break; // continue the server
}
}
if (--$nready <= 0)
continue;
}
// check the clients for incoming data.
for ($i = 0; $i <= FD_SETSIZE; $i++){
if ($client[$i] == null)
continue;
if (in_array($client[$i], $rfds)){
$n = trim(socket_read($client[$i], MAXLINE));
if (!$n)
closeClient();
else {
// if a client has sent some data, do one of these:
$n2 = explode ('#', $n);
switch ($n2[0]) {
case 'football':
// print football to other clients
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'football#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'attack':
// check password
//if ($n2[4] == $keyencryption){
// print attack to other clients
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'attack#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'admindisconnect':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'admindisconnect#'.$n2[1].'#'.$n2[3].chr(0));
}
break;
case 'magic':
// check password
//if ($n2[4] == $keyencryption){
// print magic to other clients
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'magic#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'sysping':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'sysping#'.$n2[1].'#'.$n2[4].chr(0));
}
break;
case 'systime':
if ($client[$n2[3]] != null) {
//$servertime = getdate();
$servertime = time();
socket_write($client[$n2[3]], 'systime#'.$n2[1].'#'.$servertime.chr(0));
}
break;
case 'away':
// print away status to other clients
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'away#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'busy':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'busy#'.$n2[1].'#'.$n2[4].chr(0));
}
break;
case 'buy':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'buy#'.$n2[1].'#'.$n2[4].chr(0));
}
break;
case 'buyreply':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'buyreply#'.$n2[1].'#'.$n2[4].chr(0));
}
break;
case 'personal':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'personal#'.$n2[1].'#'.$n2[4].chr(0));
}
break;
case 'personalinfo':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'personalinfo#'.$n2[1].'#'.$n2[4].chr(0));
}
break;
case 'inventory':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'inventory#'.$n2[1].'#'.$n2[4].chr(0));
}
break;
case 'inventoryinfo':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'inventoryinfo#'.$n2[1].'#'.$n2[4].chr(0));
}
break;
case 'object':
// print object to other clients
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'object#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'location':
// print location to other clients
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'location#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'location_atonce':
// print attack to other clients
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'location_atonce#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'usrinfoback':
// check password
//if ($n2[4] == $keyencryption){
// the old usr send back its own location, exist, name, room
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'usrinfoback#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'msg':
// check password
//if ($n2[4] == $keyencryption){
// print something on the server, then echo the incoming
// data to all of the clients in the $client array.
//$n is incoming data
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null && $ul[$i]['room'] == $ul[$j]['room'])
socket_write($client[$j], 'msg#'.$ul[$i]['name'].'#'.$n2[3].chr(0));
}
break;
case 'user':
// check password
//if ($n2[4] == $keyencryption){
//assign new username to array
$ul[$i] = array('name' => $n2[1], 'room' => $n2[2], 'id' => $i);
$users = getUsernames($ul[$i]["room"]);
$rooms = getRooms();
//tell username list to users in same room
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null) {
if ($ul[$i]['room'] == $ul[$j]['room']) {
socket_write($client[$j], 'enter#'.$ul[$i]['name'].'#'.$ul[$i]['id'].'#'.$n2[3].chr(0));
socket_write($client[$j], $users.chr(0));
}
socket_write($client[$j], $rooms.chr(0));
}
}
break;
case 'joinroom':
// check password
//if ($n2[4] == $keyencryption){
joinRoom($n2[1],$n2[2],$n2[3],$n2[4],$n2[5]);
break;
case 'privatemessage':
if ($client[$n2[3]] != null) {
socket_write($client[$n2[3]], 'pmsg#'.$n2[1].'#'.$n2[4].chr(0));
socket_write($client[$i], 'psmsg#'.$ul[$n2[3]]['name'].'#'.$n2[4].chr(0));
}
break;
case '/killmeonemoretime':
// check password
//if ($n2[4] == $keyencryption){
killDaemon();
//}
break;
case '/quit':
closeClient();
break;
}
}
if (--$nready <= 0)
break;
}
}
}
?>