0

I have a Jelastic environment which runs a PHP socket server that receives messages from GPS devices (which communicate via GPRS) and stores what it receives. I'm using the SocketServer.class.php class created by Navarr Barnier (link here). It's a pretty simple application as you can see:

<?php
require_once("SocketServer.class.php");
$server = new SocketServer("<server address>",20490);
$server->max_clients = 10;
$server->hook("CONNECT","handle_connect");
$server->hook("INPUT","handle_input");
$GLOBALS['conexao'] = mysql_connect('<mysql_address>', 'root', '<mysql_password>');
$GLOBALS['selected'] = mysql_select_db('<database>',$GLOBALS['conexao']);
$server->infinite_loop();

function handle_connect($server,$client,$input)
{
    SocketServer::socket_write_smart($client->socket,"OK!");
}
function handle_input($server,$client,$input)
{
  //echo "\nInput = ".$input;
  //$query = "INSERT INTO `messages`(`message`) VALUES (\"".$input."\")";
    mysql_query("INSERT INTO `messages`(`message`) VALUES ('".$input."')");
}

This code gives Issue Binding as the output, i.e it cannot create a socket at given IP:port and other IP:ports.

Actually, I've tried it all:

$server = new SocketServer("localhost",20490);
$server = new SocketServer("127.0.0.1",20490);
$server = new SocketServer("0.0.0.0",20490);
$server = new SocketServer("0",20490);
$server = new SocketServer("<server_dns>",20490);
$server = new SocketServer("<server_public_ip>",20490);

And more... All gives "Issue Binding". Any ideas on how to setup this basic socket server?

MagisterMundus
  • 335
  • 4
  • 18
  • Can you add the error message? – majidarif Apr 25 '14 at 17:05
  • The error message is "Issue Binding.", it means it could not bind to socket. – MagisterMundus Apr 25 '14 at 17:12
  • It comes from this line at the SocketServer.class.php: `socket_bind($this->master_socket,$this->config["ip"],$this->config["port"]) or die("Issue Binding");` – MagisterMundus Apr 25 '14 at 17:21
  • Are you sure that is all that its giving? Is there any warning or anything else? – majidarif Apr 25 '14 at 17:24
  • Oh, I'm sorry. I forgot about the apache logs. From all the IP addresses I used, the warnings goes from: If I use the dns or the public ip address, it says: `PHP Warning: socket_bind(): unable to bind address [98]: Address already in use in /var/www/webroot/ROOT/SocketServer.class.php on line 53`.. other ones might give `PHP Warning: socket_bind(): unable to bind address [13]: Permission denied in /var/www/webroot/ROOT/SocketServer.class.php on line 53` or `PHP Warning: socket_bind(): unable to bind address [99]: Cannot assign requested address in /var/www/webroot/ROOT/...comment too long` – MagisterMundus Apr 25 '14 at 17:49
  • Line 53 is the `socket_bind($this->master_socket,$this->config["ip"],$this->config["port"]) or die("Issue Binding");` line. – MagisterMundus Apr 25 '14 at 17:49
  • Do you have public IP enabled on your web server? You can't use sockets via the Jelastic resolver (i.e. public IP disabled) – Damien - Layershift Apr 25 '14 at 19:35
  • Hi Damien. I think I do, at least it shows a Public IP at my Apache module. I tried using the Apache public IP as the address at the socket server, but it didn't work. Any other thoughts? Thank you. – MagisterMundus Apr 25 '14 at 19:58
  • Try another port, similar by default e.g. 8001 or 8040. – leo May 06 '14 at 11:43

0 Answers0