The Little Guy Posted October 26, 2009 Share Posted October 26, 2009 In my following socket server, I am trying to listen to a connection through port 12345 in my web browser. http://127.0.0.1:12345/ I assumed that the following would detect that something was trying to connect to the port through the browser, using socket_create_listen. I don't know if I am doing something wrong or just not understanding what socket_create_listen is doing. Does anyone know why when going to the address, my socket server isn't detecting the connection? Note: The client is supposed to be the web browser, not another php file. Here is my server class: <?php set_time_limit(0); class Pherver{ private $setup; public $server; public $connections; function __construct(){ $this->setup = parse_ini_file("config.ini", TRUE); $this->server = socket_create_listen($setup['server']['port'], $etup['server']['connections']); socket_listen($this->server); } function start(){ while($client = socket_accept($this->server)){ socket_write($client, "hello"); print "here"; } } } ?> Here is how I start the server: <?php include 'Pherver.php'; $server = new Pherver(); $server->start(); ?> Thank you for the help! Link to comment https://forums.phpfreaks.com/topic/179013-solved-socket-server/ Share on other sites More sharing options...
trq Posted October 26, 2009 Share Posted October 26, 2009 Try taking a look at socket_last_error and put some debugging in your code. Link to comment https://forums.phpfreaks.com/topic/179013-solved-socket-server/#findComment-944460 Share on other sites More sharing options...
The Little Guy Posted October 26, 2009 Author Share Posted October 26, 2009 <?php set_time_limit(0); class Pherver{ private $setup; public $server; public $connections; function __construct(){ $this->setup = parse_ini_file("config.ini", TRUE); $this->server = socket_create_listen($setup['server']['port'], $etup['server']['connections']); if(!$this->server){ echo socket_last_error(); } if(!socket_listen($this->server)){ echo socket_last_error(); } } function start(){ while($client = socket_accept($this->server)){ socket_write($client, "hello"); print "here"; } } } ?> OK added, some debugging, and it doesn't give any errors... Link to comment https://forums.phpfreaks.com/topic/179013-solved-socket-server/#findComment-944463 Share on other sites More sharing options...
trq Posted October 26, 2009 Share Posted October 26, 2009 How do you know? You never actually print any of the debugging to the screen. Link to comment https://forums.phpfreaks.com/topic/179013-solved-socket-server/#findComment-944465 Share on other sites More sharing options...
The Little Guy Posted October 26, 2009 Author Share Posted October 26, 2009 yes I did I revised the previous one, and you may have missed it, but now I added some more debugging: <?php set_time_limit(0); class Pherver{ private $setup; public $server; public $connections; function __construct(){ $this->setup = parse_ini_file("config.ini", TRUE); $this->server = socket_create_listen($setup['server']['port'], $etup['server']['connections']); if(!$this->server){ echo socket_last_error(); } if(!socket_listen($this->server)){ echo socket_last_error(); } } function start(){ while(TRUE){ $client = socket_accept($this->server); if(!$client){ echo socket_last_error(); } socket_write($client, "hello"); print "here"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/179013-solved-socket-server/#findComment-944467 Share on other sites More sharing options...
The Little Guy Posted October 26, 2009 Author Share Posted October 26, 2009 Haha I got it, I was using listen in my ini file instead of port Sorry Link to comment https://forums.phpfreaks.com/topic/179013-solved-socket-server/#findComment-944469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.