Skip to content

lcherone/PHP-TCP-Socket-Client-Server

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
Apr 28, 2014
Apr 28, 2014
Apr 28, 2014

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);
?>

About

A PHP JSON TCP socket server and client.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published