Free Web Hosting Forum
(#1 (permalink))
Old
Junior Member
malebiale@o2.pl is on a distinguished road
 
Posts: 1
Join Date: Jul 2008
Smile PHP Socket Server - 07-23-2008, 09:46 AM

Hi,

Does anyone know how to set up a socket Server on 000webhost. For I know I have only uploaded the socketServer.php file that works just fine offline.(I am using php -q command to start it). When ever I am trying to access adc.net76.net/socketServer.php there is no errors print out but the browser appears to be stuck on waiting for... message.

This server is required for my flash game project that whenever I try it returns me an error message.(in flash)

Source of socket server:
Code:
#!/usr/bin/php -q
<?php
 
error_reporting(E_ALL);
 
set_time_limit(0);
 
ob_implicit_flush();
 
$address = '64.191.56.133';
$port = 1025;

$_sockets = array();
 
//---- Function to Send out Messages to Everyone Connected ----------------------------------------
 
function send_Message($allclient, $socket, $buf) {

foreach($allclient as $client) {

socket_write($client,"$socket,$buf,");

}

}
 
 
 
//---- Start Socket creation for PHP 5 Socket Server -------------------------------------
 
if (($master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {

echo "socket_create() failed, reason: " . socket_strerror($master) . "\n";

}
 
socket_set_option($master, SOL_SOCKET,SO_REUSEADDR, 1);
 
 
if (($ret = socket_bind($master, $address, $port)) < 0) {

echo "socket_bind() failed, reason: " . socket_strerror($ret) . "\n";

}
 
 
if (($ret = socket_listen($master, 5)) < 0) {

echo "socket_listen() failed, reason: " . socket_strerror($ret) . "\n";

}
else
{
  $started=time();
  echo "[".date('Y-m-d H:i:s')."] SERVER CREATED ( MAXCONN:".SOMAXCONN." ) \n";
  echo "[".date('Y-m-d H:i:s')."] Listening on ".$address.":".$port."\n";
 
}
 
 
$read_sockets = array($master);
 
//---- Create Persistent Loop to continuously handle incoming socket messages ---------------------
while (true) {

$changed_sockets = $read_sockets;
 
$num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL);
 
foreach($changed_sockets as $socket) {
 

if ($socket == $master) {
 

if (($client = socket_accept($master)) < 0) {

echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
continue;

} else {

array_push($read_sockets, $client);

echo "[".date('Y-m-d H:i:s')."] ".$client." CONNECTED "."(".count($read_sockets)."/".SOMAXCONN.")\n";
}

} else {
 

$bytes = socket_recv($socket, $buffer, 2048, 0);
 
if ($bytes == 0) {

$index = array_search($socket, $read_sockets);
unset($read_sockets[$index]);
@socket_shutdown($socket, 2);
@socket_close($socket);
/**
* Reload active clients to it's storing variable
*/             	
$allclients = $read_sockets;
echo "[".date('Y-m-d H:i:s')."] QUIT ".count($read_sockets)."\n";
}
else
{

$allclients = $read_sockets;
array_shift($allclients);
send_Message($allclients, $socket, $buffer);
}

}
 

}

}
?>
Connection is attempted at 64.191.56.133 (should be a ip of my webspace)
I uploaded a crossdomain.xml files to ensure that the flash secuirity will not termiante the connection.

Any help would be exteamlly appriciate!

Whenever project will be done I will gladly open the source for it.

Thank you
Martin
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0
vBulletin Skin developed by: vBStyles.com