TheFuteballer
asked on
Trying to create PHP Socket Server and test using Apache but socket binding problem!
So I've created a PHP based socket server and I just installed XAMMP so I have Apache, PHP, everything running locally.
Now when I try to run my socket server, I get the following error:
Warning: socket_bind() [function.socket-bind]: unable to bind address [0]: Only one usage of each socket address (protocol/network address/port) is normally permitted.
Here is the code:
<?php
// Set time limit to indefinite execution
set_time_limit (0);
// Set the ip and port we will listen on
$address = 'xxx.xxx.xxx.xxx';
$port = 9000;
$max_readers = 10;
// Array that will hold reader information
$client = array();
// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address');
The error is on that last line. I figure that it's because Apache is already listening on that port for incoming connections thus the reason why I cannot bind to it.
So my question is, how can I get Apache to NOT look at that port so I can use it for other incoming data?
Now when I try to run my socket server, I get the following error:
Warning: socket_bind() [function.socket-bind]: unable to bind address [0]: Only one usage of each socket address (protocol/network address/port) is normally permitted.
Here is the code:
<?php
// Set time limit to indefinite execution
set_time_limit (0);
// Set the ip and port we will listen on
$address = 'xxx.xxx.xxx.xxx';
$port = 9000;
$max_readers = 10;
// Array that will hold reader information
$client = array();
// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address');
The error is on that last line. I figure that it's because Apache is already listening on that port for incoming connections thus the reason why I cannot bind to it.
So my question is, how can I get Apache to NOT look at that port so I can use it for other incoming data?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.