- dumb async http server
- dumb forking http server
- dumb forking https server
- dumb http server
- dumb jsonrpc server
- dumb smtp server
- dumb soap server
- dumb syslog server
- dumb xmlrpc server
- fork with shared
- get http head
- ipc queues
- nshttpd
- persistent forking xmlrpc server
- shared obj
- simple chat server
- time server
- timer test
Click on the filename to view the highlighted source code.
simple_chat_server.php
<?php
/*
This example demonstrates how to create a simple real time IRC-like server.
Run simple_chat_server and then "telnet localhost 999" from at least two other
consoles to see it work.
*/
require "nanoserv/handlers/Telnet/Line_Input_Connection.php";
use \Nanoserv\Core as Nanoserv;
class simple_chat_server extends \Nanoserv\Telnet\Line_Input_Connection {
function on_Accept() {
$this->Send_Option(self::TYPE_WONT, self::OPT_SUPPRESS_GO_AHEAD);
$this->nick = $this->socket->Get_Peer_Name();
$this->Write("Hello ".$this->nick.", welcome to simple_chat_server.\n");
$this->Pubmsg("* {$this->nick} has joined");
}
function on_Telnet_Read_Line($s) {
if ($s[0] == "/") {
switch (strtoupper(substr(strtok($s, " "), 1))) {
case "NICK":
$newnick = trim(strtok(""));
$msg = "* {$this->nick} is now known as {$newnick}";
$this->nick = $newnick;
break;
case "ME":
$msg = "* {$this->nick} ".trim(strtok(""));
break;
}
} else {
if ($ts = trim($s)) $msg = "<{$this->nick}> {$ts}";
}
if (isset($msg)) $this->Pubmsg($msg);
}
public function on_Disconnect() {
$this->Pubmsg("* {$this->nick} has quit");
}
protected function Pubmsg($s) {
$msg = $s . "\r\n";
foreach (Nanoserv::Get_Connections() as $c) $c->Write($msg);
}
}
Nanoserv::New_Listener("tcp://[::]:999", "simple_chat_server")->Activate();
Nanoserv::Run();
?>