473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Cliente/Server with PHP

Dan
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

Jul 17 '05 #1
1 1707
"Dan" <dk****@gmail.com> wrote in message
news:10*********************@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?
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil | last post by:
I am using a Pascal like language (Wealth-Lab) on W2K and call this server: class HelloWorld: _reg_clsid_ = "{4E797C6A-5969-402F-8101-9C95453CF8F6}" _reg_desc_ = "Python Test COM Server"...
6
by: Nathan Sokalski | last post by:
I want to set up SQL Server on Windows XP Pro so that I can use the database capabilities of ASP and IIS. I am probably using some incorrect settings, but I am not sure what they are. Here is what...
2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
1
by: Liber | last post by:
Utilizando .Net, como puedo obtener la dirección ip o el nombre del cliente remoto que está conectado por Terminal Service a un Servidor de Terminal ? En el Terminal Servide Manager me muestra el...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
14
by: Developer | last post by:
Hello All, i have recently installed VS2005 and was trying to install SQL sever 2000. I have Win XP' SP2. But when I tried installing, it only installed client tools and not the database. Can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.