- Important Classes & Interfaces
- Important Directories
Network is a component that provides possibility to create standalone, asynchronous servers supporting various network protocols, including TCP, HTTP and WebSockets.
- 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.
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:
When you have created instance of server, the routes can be added via
$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
unblockAddress methods, for example:
$server->blockAddress('188.8.131.52'); // 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.
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.
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.