A PHP JSON TCP socket server and client.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 1e262b0 Apr 28, 2014
Permalink
Failed to load latest commit information.
lib Initial Commit Apr 28, 2014
.gitattributes Initial Commit Apr 28, 2014
.gitignore Initial Commit Apr 28, 2014
README.md Update README.md Apr 28, 2014
index.php Update index.php Apr 28, 2014
server.php Initial Commit Apr 28, 2014

README.md

PHP-TCP-Socket-Client-Server

A simple stripped down PHP TCP socket server and client, that communicates in JSON format; wrapped in a handy class. Server will parse the JSON and call controller based on route, currently its very bare and does nothing but sends JSON back. In later commits ill add something more interesting.

Example:

./index.php (Client) Client builds and sends a JSON encoded packet.

<?php
require('./lib/socket.class.php');
require('./lib/socketClient.class.php');

$socket = new socketClient('127.0.0.1', 54321);

$packet = array('controller'    => 'index',
				'action'	    => 'index',
				'subaction'	    => '',
				'subaction_id'  => '',
				'time'		    => time(),
				'ip'		    => $_SERVER['SERVER_ADDR'],
				);

$response = $socket->send(json_encode($packet));

$socket->report();
?>

./server.php (Server)

<?php
require('./lib/socket.class.php');
require('./lib/socketServer.class.php');

new socketServer("0.0.0.0", 54321);
?>