You don't need frames to view this website. Flash communication server. Flash mx xml socket server.
Home
Main Menu
Home
- - - - - - -
What is Palabre ?
Features
News
FAQ
Forum
DEMO
- - - - - - -
Downloads !
Browse SVN
- - - - - - -
Search
Contact Us
- - - - - - -
Sourceforge Project Page
Python
Links




 
Download Palabre Flash Xml Socket Server DOWNLOAD Download Palabre Flash Xml Socket Server FORUM Download Palabre Flash Xml Socket Server FAQ Download Palabre Flash Xml Socket Server WHAT IS IT
 



Using Palabre ? Coming here for Support ? Please consider making an (even small) donation :)
Palabre Forum  


::post new topic::
php / telnet connect to palabre - 2008/06/28 12:21 Hi,

I'am trying to connect via php to the palabre server, but somehow I can't figure it out. This is my script so far:

Code:

 <?php header("Content-Type: text/html"); echo "Connecting to Palabre<br><br>"; /* connection data */ $service_host "localhost"; $service_port 2468; /* create socket */ echo "creating socket...<br>"; $socket socket_create(AF_INETSOCK_STREAMSOL_TCP); if ($socket === false) {     echo "socket_create() aborted: Reason: " socket_strerror(socket_last_error()) . "<br><br>"; } else {     echo "socket_create() OK.<br><br>"; } echo "connecting to '$service_host' on port '$service_port'  ...<br>"; $result socket_connect($socket$service_host$service_port); if ($result === false) {     echo "socket_connect() aborted: Reason: ($result) " socket_strerror(socket_last_error($socket)) . "<br><br>"; } else {     echo "socket_connect() OK.<br><br>"; } $out "<getrooms  />\n"; $in ''; echo "sending request: $out<br>"; socket_write($socket$outstrlen($out)); echo "socket_write() OK.<br><br>"; echo "retrieving response...<br><br>"; while ($in socket_read($socket2048)) {    echo $in; } echo "close socket ...<br>"; socket_close($socket); echo "OK.<br><br>"; ?>



I run it in a IE window for testings.

But it runs forever without getting a response.

When I comment out this lines:

Code:

  echo "retrieving response...<br><br>"; while ($in socket_read($socket2048)) {    echo $in; }



then I get back my debug output and I can see that the connection is established and the data is sent.

Code:

 Connecting to Palabre creating socket... socket_create() OK. connecting to 'localhost' on port '2468' ... socket_connect() OK. sending requestsocket_write() OK. close socket ... OK.



Now I tried to figure out exactly what I need to send to palabre in regards of /r/n (CRLF), so I thought it might be a good idea to play around with telnet first.

But same with telnet. When I connect and try to type in "<connect nickname='mike' />" it does not answer at all.

At this point more debugging options would help a lot :-)

I use a windows machine and I found in the readme of the SVN there is a comment about a 'null' after each character for telnet sessions, but I don't understand what that means.

Can somebody help me figuring out what my script needs to send or where my mistake is?

Regards, Mike
  reply | quote
Re:php / telnet connect to palabre - 2008/06/28 13:37 Hi,

Flash xml socket function is using the "null byte" as a delimiter
so instead of n or r try using (backslash zero)
I don't remember the telnet equivalent

have fun
  reply | quote
Re:php / telnet connect to palabre - 2008/06/28 13:38 0
  reply | quote
Re:php / telnet connect to palabre - 2008/06/28 14:08 How can I perforam a telnet test célio ?

Could you describe that to me , sorry I'am lost a little.

How can I send such a null byte char to telnet or within my php coding?

Thansk a lot, Mike
  reply | quote
Re:php / telnet connect to palabre - 2008/06/28 14:16 ohhh I see it id "baclslash 0" :-) The forum does not like the baclslash :-)

I will post my result once I figured it out completly.

Corrently my while loop, loops forever, don't know why.

But I got the respone already from the server, yeah, thanks.

Regards, Mike
  reply | quote
Re:php / telnet connect to palabre - 2008/06/30 10:17 Hi all,

I figured out my problem.

The script is now working fine, here is the sniplet if you are interested:

Code:

  <?php header("Content-Type: text/html"); echo "Connecting to Palabre<br><br>"; /* connection data */ $service_host "localhost"; $service_port 2468; /* create socket */ echo "creating socket...<br>"; $socket socket_create(AF_INETSOCK_STREAMSOL_TCP); if ($socket === false) {     echo "socket_create() aborted: Reason: " socket_strerror(socket_last_error()) . "<br><br>"; } else {     echo "socket_create() OK.<br><br>"; } /* set socket receive timeout to 2 second */ socket_set_option($socketSOL_SOCKETSO_RCVTIMEO, array("sec" => 2"usec" => 0)); echo "connecting to '$service_host' on port '$service_port'  ...<br>"; $result socket_connect($socket$service_host$service_port); if ($result === false) {     echo "socket_connect() aborted: Reason: ($result) " socket_strerror(socket_last_error($socket)) . "<br><br>"; } else {     echo "socket_connect() OK.<br><br>"; } //sending stuff here echo "Send process<br>"; $out "<connect nickname=\"Nickname\" />\0"; $in ''; echo "SEND: $out <br>"; socket_write($socket$outstrlen($out)); echo "RECV: "; while ($in socket_read($socket2048PHP_BINARY_READ)) {    echo $in; } echo "<br><br>"; $out "<quit />\0"; $in ''; echo "SEND: $out <br>"; socket_write($socket$outstrlen($out)); echo "close socket ...<br>"; socket_close($socket); echo "OK.<br><br>"; ?>



You're still getting a error in the while loop because the socket is only open for 2 sec and then the while loop ends with a socket_read error.

If you know exactly the response lenght you can also make a single statement of socket_read instead of the while loop to work around the warning message.

Nevertheless the result of the experiment is bad for me, because I had a major error in my idea.

A PHP script called via HTTP is stateless and not designed to have a infinite loop running which listens to a socket. The output of a PHP script is sent to the browser once the script finished sucessfully. But I planned to have is running over a longer period of time until a user quits the session.

So PHP works only if you want to build something on server side where a script but run in a infinite loop.

If somebody has a idea how I could write a socket client with PHP please tell me.

My current ideas are:
- trying out something with AJAX (asynchronouse Javascript and XML) and HTTP polling to a PHP script , which then connects to the socketserver to refresh the client. AJAX is able to update the browser content without a reload. (see this chat example: http://www.linuxuser.at/chat/index.html
- building a hidden frame (technique seems to be called COMET) where a infinite loop runs to request the data from the socket server and give them to another frame whee it is shown. But don't know how to do that.

Why do I try that stuff. I'll try to build a little multiplayer game, but I have no clue about Flash. So I need to figure out something in PHP or Javascript.

There are already good games with AJAX around, see this german example: http://www.travianer.de/ (Just click around on the map to see the character moving around.

Regards, Mike
  reply | quote
::post new topic::