Socket Server


Posted on 16th Feb 2014 07:03 pm by admin

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:
Code: [Select]<?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:
Code: [Select]<?php
include 'Pherver.php';
$server = new Pherver();
$server->start();
?>
Thank you

No comments posted yet

Your Answer:

Login to answer
324 Like 31 Dislike
Previous forums Next forums
Other forums

Problem with DB connection
Hello there! I'm new to this forum and I'm new to PHP coding also. I wrote something that doesn't ma

Parse XML
Good day,

I use oempro software and try to parse XMLReturn but it's not working for me, simpl

Help with usergroups? prolly really quick
So were coding our own forums for a game system we made an we have the users level setup but now I n

fwrite error
Hi All,
Does anyone know what is causing the error in this code?

Code: <?
$error

batch file not building to webapps folder
Hello. I just started running Vista :P and can't seem to get my projects deployed. I found out how

Sharing PHP Sessions Across Domains
I am in the process of writing a script to share a php session across various domains I have.
The

License Issue - service type user
Hi,

I would like to understand the following issue regarding sap license.
I wish to

Echoing If Function?
A script I am using has If statements in the comments form to basically tell the form what to do. Cu

Port scanner problem
Hai
recently i developed one app through which u can check the opened and closed ports under an

=> and <=
So I was digging through some code when I came across the <= operator. This is the first tim

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash