isathais1 / tcp-socket
TCP Socket for Laravel 5
dev-master
2018-04-13 18:42 UTC
Requires
- php: >=5.6.4
- illuminate/support: 5.*
This package is not auto-updated.
Last update: 2024-09-22 09:03:43 UTC
README
installation
For install this package Edit your project's composer.json
file to require isathais1/tcp-socket
"require": { "isathais1/tcp-socket": "dev-master" },
Now, update Composer:
composer update
Once composer is finished, you need to add the service provider. Open config/app.php
, and add a new item to the providers array.
'isathais1\Socket\SocketServiceProvider',
Next, add a Facade for more convenient usage. In config/app.php
add the following line to the aliases array:
'Socket' => 'isathais1\Socket\Facades\Socket',
Publish config files:
php artisan vendor:publish --provider="isathais1\Socket\SocketServiceProvider"
for change username, password and other configuration change config/tcp-socket.php
Usage
###Configuration
Open config/tcp-socket.php
Enter Server Ip Address and Port
You can change server protocol between SOL_TCP
and SOL_UDP
Connect To Server
Socket::connect(); Socket::connect($ip); Socket::connect(null, $port); Socket::connect($ip, $port);
Disconnect from Server
Socket::disconnect();
Send Message
Socket::sendMessage('test message'); //send message to connected server Socket::sendMessageTo('test message', 'server ip', server port) // send message to a socket
Read Message
$response = Socket::readMessage(); //Read message with 2048 byte buffer Or $response = Socket::readMessage($length)//Read message with custom byte buffer; $response = Socket::readMessage($length,$type)//Read message with custom byte buffer and custom type(PHP_NORMAL_READ or PHP_BINARY_READ);