marks12/socketserverbundle

安装: 91

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 0

公开问题: 0

类型:symfony-bundle

0.3.0 2016-12-08 11:42 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:33:50 UTC


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.