Jump to content

Sockets: Could not accept incoming connection


php-n00b

Recommended Posts

Ahoy Sailor!

 

So I've just started making a Server Client based application in PHP, First time I've dabble in PHP for about a year so forgive me if I'm slightly rusty. But I get the "Could not accept incoming connection" error when my client try's to connect to my server. How cometh?

 

<?php
$host = "127.0.0.1";
$port = 405;
set_time_limit(0);
// create socket
$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 listener\n");
// Networking area, Creating, Binding & finally listing

$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");

$out = "0;text\n";
socket_write($spawn, $out, strlen ($out)) or die("Could not write output\n");

?>

^ Client

<?php
$addr="127.0.0.1";
$port=405;
$timeout=0;
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$res = socket_connect($socket, $addr, $port);

$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
$dat= socket_read($spawn, 1024) or die("Could not read input\n");
echo $dat;
?>

Server^

_____________________

 

Anyone know?

 

See Ya!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.