thruster / socket
Thruster Socket Component
Requires
- php: >=7.0
- thruster/event-emitter: ~1.0
- thruster/event-loop: ~1.0
- thruster/stream: ~1.0
Requires (Dev)
- phpunit/phpunit: ~5.0
This package is auto-updated.
Last update: 2024-12-14 03:33:55 UTC
README
[] (https://github.com/ThrusterIO/socket/releases) [] (LICENSE) [] (https://travis-ci.org/ThrusterIO/socket) [] (https://scrutinizer-ci.com/g/ThrusterIO/socket) [] (https://scrutinizer-ci.com/g/ThrusterIO/socket) [] (https://packagist.org/packages/thruster/socket)
The Thruster Socket Component.
Library for building an evented socket server.
The socket component provides a more usable interface for a socket-layer
server or client based on the EventLoop
and Stream
components.
Server
The server can listen on a port and will emit a connection
event whenever a
client connects.
Connection
The Connection
is a readable and writable Stream
.
The incoming connection represents the server-side end of the connection.
It MUST NOT be used to represent an outgoing connection in a client-side context.
If you want to establish an outgoing connection,
use the SocketClient
component instead.
Install
Via Composer
$ composer require thruster/socket
Usage
Here is a server that closes the connection if you send it anything.
$loop = new EventLoop(); $socket = new Server($loop); $socket->on('connection', function ($conn) { $conn->write("Hello world!\n"); $conn->on('data', function ($data) use ($conn) { $conn->close(); }); }); $socket->listen(1337); $loop->run();
You can change the host the socket is listening on through a second parameter provided to the listen method:
$socket->listen(1337, '192.168.0.1');
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
License
Please see License File for more information.