Network is a component that provides possibility to create standalone, asynchronous servers supporting various network protocols, including TCP, HTTP and WebSockets.
Network features:
Solver is an abstraction of a measure that have to be taken to solve problem which occurred.
This section contains examples and patterns that can be used with described component.
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();
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
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
This section contains list of most important classes and interfaces shipped with this component. It does not include all classes and interface.
class NetworkServer implements NetworkServerInterface
NetworkServer is an instance of universal server that allows route-based handling of various network protocols.
interface NetworkServerInterface extends LoopResourceInterface
class NetworkConnection implements NetworkConnectionInterface
NetworkConnection is an instance of incoming connection. Each connection represents one computer or another server connecting to your application.
interface NetworkConnectionInterface extends RatchetConnectionInterface
class NetworkMessage implements NetworkMessageInterface
NetworkMessage is an instance of incoming message or part of message in case of multi-part communication.
interface NetworkMessageInterface
interface ServerComponentInterface
ServerComponentInterface is an interface that have to be implemented by each of server's components.
This section contains list of most important subdirectories placed inside this component. It does not include all its subdirectories.
Http directory contains HTTP server wrapper and all of its components.
Socket directory contains TCP server wrapper and all of its components.
Websocket directory contains Websocket server wrapper and all of its components.