marks12 / socketserverbundle
0.3.0
2016-12-08 11:42 UTC
Requires
- php: >=7.0
- doctrine/doctrine-bundle: *
- doctrine/orm: ^2.5
- symfony/symfony: 3.1.*
README
该模块允许在端口10000上打开新的多用户socket服务器并调用您的类。
安装
通过composer安装此模块
composer require marks12/socketserverbundle
配置
添加到config/config.yml
marks12_socket_server:
class: 'AppBundle\Socket\ResponseFactoryExample'
address: '0.0.0.0'
port: '10000'
创建类
在您的应用程序中创建类 AppBundle\Socket\ResponseFactoryExample.php
<?php namespace AppBundle\Socket; class ResponseFactoryExample { function run ($data, $em, $answer_object) { $msg = 'Hello, this is class run in ServerProduct. Data: ' . $data . PHP_EOL; $answer_object->answer($msg); } }
使用
启动您的socket服务器
bin/console marks12:socket:start
连接到服务器
telnet localhost 10000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Welcome to server: Send exit for disconnect
test
Hello, this is class run in ServerProduct. Data: test
Hello, this is class run in ServerGhost. Data: test
exit
Connection closed by foreign host.