dev-master
9999999-devTCP Socket for Laravel 5
MIT
The Requires
- php >=5.6.4
- illuminate/support 5.*
by Isa Thais
TCP Socket for Laravel 5
For install this package Edit your project's composer.json
file to require isathais1/tcp-socket, (*1)
"require": { "isathais1/tcp-socket": "dev-master" },
Now, update Composer:, (*2)
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., (*3)
'isathais1\Socket\SocketServiceProvider',
Next, add a Facade for more convenient usage. In config/app.php
add the following line to the aliases array:, (*4)
'Socket' => 'isathais1\Socket\Facades\Socket',
Publish config files:, (*5)
php artisan vendor:publish --provider="isathais1\Socket\SocketServiceProvider"
for change username, password and other configuration change config/tcp-socket.php
, (*6)
Open config/tcp-socket.php
br/
Enter Server Ip Address and Port
You can change server protocol between SOL_TCP
and SOL_UDP
, (*7)
Socket::connect(); Socket::connect($ip); Socket::connect(null, $port); Socket::connect($ip, $port);
Socket::disconnect();
Socket::sendMessage('test message'); //send message to connected server Socket::sendMessageTo('test message', 'server ip', server port) // send message to a socket
$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);
TCP Socket for Laravel 5
MIT