swoole 创建tcp服务器
server.php
<?php
/**
* 创建tcp服务器
* Date: 2019/1/15
*/
$serv = new swoole_server('127.0.0.1', 9501); // 监听连接进入事件
$serv->on('connect', function ($serv, $fd) {
echo "Client: Connect.\n";
}); // 监听数据接收事件
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
$serv->send($fd, "Server: " . $data);
}); // 监听连接关闭事件
$serv->on('close', function ($serv, $fd) {
echo "Client: Close.\n";
}); // 启动服务器
$serv->start();
1.执行程序,启动服务器
$ sudo /usr/local/php/bin/php server.php
Client: Connect.
2. 启动成功后,netstat 查看
$ sudo netstat -ntlp | grep php
tcp 127.0.0.1: 0.0.0.0:* LISTEN /php
3. telnet连接服务器
$ telnet 127.0.0.1
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
hello
Server: hello
退出telnet:shift+],quit
4. 结束工作进程:kill 主进程ID
$ kill
参考:https://wiki.swoole.com/wiki/
swoole 创建tcp服务器的更多相关文章
- Swoole学习(二)Swoole之TCP服务器的创建
环境:Centos6.4,PHP环境:PHP7 <?php //创建TCP服务器 /** * $host 是swoole需要监听的ip,如果要监听本地,不对外服务,那么就是127.0.0.1;如 ...
- 【Swoole】简单安装与创建TCP服务器
pecl install swoole PHP的异步.并行.高性能网络通信引擎,使用纯C语言编写,提供了php语言的异步多线程服务器,异步TCP/UDP网络客户端,异步MySQL,异步Redis,数据 ...
- 使用nodejs的net模块创建TCP服务器
使用nodejs的net模块创建TCP服务器 laiqun@msn.cn Contents 1. 代码实现 2. 使用telnet连接服务器测试 3. 创建一个TCP的client 1. 代码实现 ; ...
- swoole创建websocket服务器
目录 1 安装准备 1.1 安装swoole前必须保证系统已经安装了下列软件 1.2 下载并解压 1.3 编译安装成功后,修改php.ini 2 构建Swoole基本实例 2.1 tcp服务器实例 2 ...
- swoole 创建UDP服务器
udp_server.php <?php // 创建Server对象,监听 127.0.0.1:9502端口,类型为SWOOLE_SOCK_UDP $serv = new swoole_serv ...
- swoole创建TCP服务端和客户端
服务端: server.php <?php //创建Server对象,监听 127.0.0.1:9501端口 $serv = new swoole_server("127.0.0 ...
- swoole 创建web服务器
http_server.php $http = new swoole_http_server("0.0.0.0", 9501); // 请求监听事件 $http->on('r ...
- 创建TCP服务器和TCP客户端
import sockethost='127.0.0.1'port=8080web=socket.socket()web.bind((host,port))web.listen(5)# 设置最多连接数 ...
- 使用net模块创建tcp服务器
demo /** * Created by ZXW on 2018/4/6. */ var net=require('net'); ; const HOST='localhost'; var clie ...
随机推荐
- Python——爬取百度百科关键词1000个相关网页
Python简单爬虫——爬取百度百科关键词1000个相关网页——标题和简介 网站爬虫由浅入深:慢慢来 分析: 链接的URL分析: 数据格式: 爬虫基本架构模型: 本爬虫架构: 源代码: # codin ...
- jQuery练习 | 模态对话框(添加删除)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- (转)shell变量及扩展
1.shell变量 shell变量赋值语句为”name=[value]“,等号两边不能有空格,可以给shell变量追加内容”name+=value“,取消shell变量的设置使用”unset name ...
- chrome浏览器开发者工具(一)
一.Elements 在Element中主要分两块大的部分:HTML结构面板和操作dom样式.结构.时间的显示面板 二.Network Network是一个监控当前网页所有的http请求的面版,它主体 ...
- Jquery执行效率提高的方法
1.选择器性能排行:$("#ID") > $("Tag") > $(".Class") > $("[attrib ...
- Redis数据持久化机制AOF原理分析一---转
http://blog.csdn.net/acceptedxukai/article/details/18136903 http://blog.csdn.net/acceptedxukai/artic ...
- jQuery ajax async
jQuery 同步调用: jQuery.ajax({ type:'POST', async: false, url:'qcTask/add', contentType:'application/jso ...
- 微信小程序准备阶段。(一)
--知识储备--HTML+JS+CSS (一)下载一个微信web开发工具(后续代码都会写在这里边)附上链接:https://mp.weixin.qq.com/debug/wxadoc/dev/devt ...
- (C++学习)关于CString的一些疑问
#include <iostream> #include <string> #include <afx.h> #include <vector> usi ...
- C++命名空间使用代码
namesp.h #pragma once #include <string> namespace pers { using namespace std; struct Person { ...