I've run into a problem, and I hope you guys might know where I'm going wrong.
I'm trying to send and receive information through PHP to my running JAVA program.
The program is the knockknockserver.
The PHP-code im using is this:
$host='127.0.0.1';
$port=4444;
$socket=socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not
create socket \n");
$result=socket_bind($socket, $host, $port) or die("Could not bind to
socket\n");
$result=socket_listen($socket, 3) or die('Could not set up socket
listenern');
$spawn=socket_accept($socket) or die('Could not accept incoming
connection');
$input=socket_read($result, 1024) or die('Could not read input');
socket_close($spawn);
socket_close($socket);
I just grabbed from the net.
Ideally the interaction would be that I connect to the port 4444, then the Java server responds knock knock!.
The problem I'm having is that, if i run Java server first the PHP script fails to bind the socket (I'm guessing since it's already in use).
And sometimes the socket_accept just makes my browser jam, so I have to entirely restart it to get it working again.
What I'm really trying to do is learn how to communicate through ports, I've been trying to read, but I just don't understand why I cannot connect and accept communication through an already open port.
Could not bind to socket\n?