Skip to content

Latest commit

 

History

History
144 lines (96 loc) · 4.59 KB

api-network.md

File metadata and controls

144 lines (96 loc) · 4.59 KB

Network Component

Introduction

Network is a component that provides possibility to create standalone, asynchronous servers supporting various network protocols, including TCP, HTTP and WebSockets.

Features

Network features:

- Asynchronous TCP server - Asynchronous HTTP/1.1 server - Asynchronous WebSocket server with support for RFC6455 and HyBi10 protocols - Connections firewall - HTTP request and response abstraction - HTTP routing - HTTP session provider - Kraken Framework compatibility

Solver is an abstraction of a measure that have to be taken to solve problem which occurred.

Examples

This section contains examples and patterns that can be used with described component.

Creating Network Server

Network server can be used like this:

$listener = new SocketListener('tcp://127.0.0.1:8080', $loop);
$server   = new NetworkServer($listener);

After you are done with server it can be closed using:

$server->stop();

Using Routes

When you have created instance of server, the routes can be added via addRoute method.

$server->addRoute('/', new IndexAction); // HTTP GET /
$server->addRoute('/other', new OtherAction); // HTTP GET /other
$server->addRoute('/chat', new WsServer(null, new Chat)); // ws://localhost:8080/chat

Using Firewall

Firewall is placed under Kraken\Network\Socket\Component\Firewall. If you are using default NetworkServer it has this component created by default. You can use it via blockAddress and unblockAddress methods, for example:

$server->blockAddress('75.252.8.24'); // will deny access for this ip

Important Classes & Interfaces

This section contains list of most important classes and interfaces shipped with this component. It does not include all classes and interface.

NetworkServer

class NetworkServer implements NetworkServerInterface

NetworkServer is an instance of universal server that allows route-based handling of various network protocols.

NetworkServerInterface

interface NetworkServerInterface extends LoopResourceInterface

NetworkConnection

class NetworkConnection implements NetworkConnectionInterface

NetworkConnection is an instance of incoming connection. Each connection represents one computer or another server connecting to your application.

NetworkConnectionInterface

interface NetworkConnectionInterface extends RatchetConnectionInterface

NetworkMessage

class NetworkMessage implements NetworkMessageInterface

NetworkMessage is an instance of incoming message or part of message in case of multi-part communication.

NetworkMessageInterface

interface NetworkMessageInterface

ServerComponentInterface

interface ServerComponentInterface

ServerComponentInterface is an interface that have to be implemented by each of server's components.

Important Directories

This section contains list of most important subdirectories placed inside this component. It does not include all its subdirectories.

Http

Http directory contains HTTP server wrapper and all of its components.

Socket

Socket directory contains TCP server wrapper and all of its components.

Websocket

Websocket directory contains Websocket server wrapper and all of its components.