Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 25th, 2004, 08:08 AM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Basilar problems in programmming with socket

Hi everyone,
first of all sorry for my bad English
I've started programming with socket in php (yes, I'm a newbie) and I've already a problem which doesn't allow me to go forward.
Hope you can help me...
I've tried to use the entire code token from the article called 'Socket Programming With PHP' but it doesn't work properly under win xp.
It comes out this error
-- Warning: socket_bind() unable to bind address [10048]: Di norma è consentito un solo utilizzo di ogni indirizzo di socket (protocollo/indirizzo di rete/porta). in c:\programmi\apache group\apache\htdocs\test\socket\socket.php3 on line 14
Could not bind to socket

Total translation should be:
-- Warning: socket_bind() unable to bind address [10048]: basely it is allowed a unique address of socket (protocol/network address/port). in c:\programmi\apache group\apache\htdocs\test\socket\socket.php3 on line 14
Could not bind to socket

Here the configuration: apache/1.3.27 (Win32) PHP/4.3.4

Here the code:
--- socket.php3 ---
<?

// set some variables
$host = "127.0.0.1";
$port = 1234;

// don't timeout!
set_time_limit(0);

// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create
socket\n");

// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to
socket\n");

// start listening for connections
$result = socket_listen($socket, 3) or die("Could not set up socket
listener\n");

// accept incoming connections
// spawn another socket to handle communication
$spawn = socket_accept($socket) or die("Could not accept incoming
connection\n");

// read client input
$input = socket_read($spawn, 1024) or die("Could not read input\n");

// clean up input string
$input = trim($input);

// reverse client input and send back
$output = strrev($input) . "\n";
socket_write($spawn, $output, strlen ($output)) or die("Could not write
output\n");

// close sockets
socket_close($spawn);
socket_close($socket);
?>

Thanks a lot to all in advance!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket Progrmming sudhirbharti C# 2005 2 February 21st, 2008 03:54 AM
Socket connections hockney General .NET 1 July 6th, 2005 04:14 AM
Socket Programming ashu_from_india General .NET 0 June 28th, 2005 12:02 PM
Socket programming vinodkalpaka J2EE 0 June 16th, 2005 02:43 AM
Socket Programming chinni Pro PHP 1 August 18th, 2003 03:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.