Socket Server Response Headers

Posted on 16th Feb 2014 by admin

Earlier I had a post about my Socket Server, I wasn't able to get it to connect, now I can

I am using socket_write() to well hopefully send html to a web page, the problem I think is that I have to send Response Headers, but I am not sure how to do that. Is that what I need to do? Currently the page just sits there and loads, it connects to the sockets, but nothing ever shows up on the page, so that is why I think I also have to send response headers... Is that correct?

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($this->setup['server']['port'], $this->setup['server']['connections']);
if(!$this->server){
echo socket_last_error();
}
if(!socket_listen($this->server)){
echo socket_last_error();
}
echo "Pherver Service Started!n";
echo "Listening on port: ".$this->setup['server']['port']."n";
}
function start(){
while(TRUE){
$client = socket_accept($this->server);
if(!$client){
echo socket_last_error();
}else{
$msg = "<html><body><h1>Hello</h1></body></html>";
socket_write($client, $msg);
}
}
}
}
?>

Other forums