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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.