Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Newbie | Attempting connecting a port to a listener

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Newbie | Attempting connecting a port to a listener

Postby mikeincousa » Sun Sep 08, 2013 1:59 pm

First I tested the connection.
Local Client $ nc [ip address] 6023
Hosted server nc -l 6023
#Text flows from one to the other as expected

Next, a tutorial and debugging led me to this script:

*************
<?
$host = "0.0.0.0" ;
$port = 6023;
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, 6023) or die("Could not set up socket listener\n");
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
$input = socket_read($spawn, 1024) or die("Could not read input\n");
$input = trim($input);
$output = strrev($input) . "\n";
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
socket_close($spawn);
socket_close($socket);
?>

“****************************************
It seems to work okay in my local machine, in that it returns a blinking cursor. But--I cannot access it from afar because my local machine lies behind a shared IP address.

When I run the exact same script under my dedicated IP address at Bluehost, it does not throw an error that registers in Cpanel. But--when I run from the command line in my local machine connected through SSH it throws this error.

Failed loading /usr/php/54/usr/lib64/php/modules/ZendGuardLoader.so:  /usr/php/54/usr/lib64/php/modules/ZendGuardLoader.so: undefined symbol: zend_new_interned_string
Content-type: text/html

Earlier testing shows the bind command works.

Inching down the script, it seems to stall on the accept command.

I tried integrating commads like socket_set_noblock but did have any cofidence I had them right of if they are needed.

Bluehost L1 & L2 support techs had no thoughts. They moved this issues to L3 earlier today.

Querrying the web indicates the stall could lie in the rolling of the php.ini file??? (Sorting out much more is beyind me for now.)

Anyone have any ideas for getting this going? Another way to test it?

Thanks
mikeincousa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Jun 26, 2013 8:17 pm

Re: Newbie | Attempting connecting a port to a listener

Postby johnj » Mon Sep 09, 2013 8:07 pm

please write appropriate error handling routines in your code. without this, it will be difficult for you to know what is going wrong.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Newbie | Attempting connecting a port to a listener

Postby mikeincousa » Mon Sep 16, 2013 7:02 pm

So far I've been relying on the “ ...or die” statement in commands.

Which code tracer / debugger do you suggest for a newbie?

Where should I start for a more sophisticate track?

http://php.net/manual/en/ref.errorfunc.php

I'd like to to trace script progress line by line.
mikeincousa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Jun 26, 2013 8:17 pm

Re: Newbie | Attempting connecting a port to a listener

Postby johnj » Mon Sep 16, 2013 10:56 pm

CodeLobster is a good editor, it has a debugger
http://phillipnb.wordpress.com/2012/11/ ... delobster/

If not, you can also use eclipse for php

If not, use any text editor and write your error routines. Even you can use the simple "echo()" and see where (which line) this is crashing and there try to print the error message using error_get_last() or even using try catch.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 6 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.