Cliente/Server with PHP

This is a discussion on Cliente/Server with PHP within the PHP Language forums, part of the PHP Programming Forums category; Im trying to figure out the problem with a very simple client/server program written in PHP. Ill post the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-22-2004
Dan
 
Posts: n/a
Default Cliente/Server with PHP

Im trying to figure out the problem with a very simple client/server
program written in PHP.

Ill post the php code of the server and the client, both are based on
the annotated PHP Help.

The server will only write a message to a cliente every time one
connects to it.

Server Code:
<?
$direccion = '0.0.0.0';
$puerto = 4321;


if (($serverSocket = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) {
echo socket_strerror ($serverSocket) . "\n";
}


if (($retorno = socket_bind ($serverSocket, $direccion, $puerto)) < 0)
{
echo socket_strerror ($retorno) . "\n";
}


if (($retorno = socket_listen ($serverSocket, 1)) < 0) {
echo socket_strerror ($retorno) . "\n";
}


do {
if (($cliente = socket_accept($serverSocket)) < 0) {
echo socket_strerror ($cliente) . "\n";
break;
}
$mensaje = "bienvenido al server\n";
socket_write($cliente, $mensaje, strlen($mensaje));



//socket_close ($msgsock);
} while (true);
socket_close ($sock);

?>

Client Code:
<?php
error_reporting (E_ALL);

echo "<h2>TCP/IP Connection</h2>\n";


$service_port = 4321;


$address = '127.0.0.1';

/* Create a TCP/IP socket. */
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror ($socket)
.. "\n";
} else {
echo "OK.\n";
}

echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect ($socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " .
socket_strerror($result) . "\n";
} else {
echo "OK.\n";
}


$out = '';


echo "Reading response:\n\n";
while ($out = socket_read ($socket, 2048)) {
echo $out;
}

echo "Closing socket...";
socket_close ($socket);
echo "OK.\n\n";
?>

Both pages are uploaded to the web, and both are in the same folder:
/server.php and /client.php. When I try to access the server page, it
stays waiting, and in a different client I try to access the client
page and it also stays waiting, without doing anything.

Anybody has any ideas what the problema is?
Thanks in advance,
Daniel Kawer

Reply With Quote
  #2 (permalink)  
Old 09-23-2004
Chung Leong
 
Posts: n/a
Default Re: Cliente/Server with PHP

"Dan" <dkawer@gmail.com> wrote in message
news:1095813569.401863.90130@k17g2000odb.googlegro ups.com...
> Both pages are uploaded to the web, and both are in the same folder:
> /server.php and /client.php. When I try to access the server page, it
> stays waiting, and in a different client I try to access the client
> page and it also stays waiting, without doing anything.
>
> Anybody has any ideas what the problema is?
> Thanks in advance,
> Daniel Kawer


session.auto_start is on?


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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




All times are GMT +1. The time now is 07:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0