当前位置:网站首页>TCP补充
TCP补充
2022-08-08 13:46:00 【932我】
TCP 相关实验TCP 相关实验
理解 listen 的第二个参数
对于服务器, listen 的第二个参数设置为 2, 并且不调用 accept
test_server.cc
#include "tcp_socket.hpp"
int main(int argc, char* argv[]) {
if (argc != 3) {
printf("Usage ./test_server [ip] [port]\n");
return 1;
}
TcpSocket sock;
bool ret = sock.Bind(argv[1], atoi(argv[2]));
if (!ret) {
return 1;
}
ret = sock.Listen(2);
if (!ret) {
return 1;
}
// 客户端不进行 accept
while (1) {
sleep(1);
}
return 0; }#include "tcp_socket.hpp"
int main(int argc, char* argv[]) {
if (argc != 3) {
printf("Usage ./test_client [ip] [port]\n");
return 1;
}
TcpSocket sock;
bool ret = sock.Connect(argv[1], atoi(argv[2]));
if (ret) {
printf("connect ok\n");
} else {
printf("connect failed\n");
}
while (1) {
sleep(1);
}
return 0; }tcp 3 0 0.0.0.0:9090 0.0.0.0:* LISTEN
9084/./test_server
tcp 0 0 127.0.0.1:9090 127.0.0.1:48178 SYN_RECV -
tcp 0 0 127.0.0.1:9090 127.0.0.1:48176 ESTABLISHED -
tcp 0 0 127.0.0.1:48178 127.0.0.1:9090 ESTABLISHED
9140/./test_client
tcp 0 0 127.0.0.1:48174 127.0.0.1:9090 ESTABLISHED
9087/./test_client
tcp 0 0 127.0.0.1:48176 127.0.0.1:9090 ESTABLISHED
9088/./test_client
tcp 0 0 127.0.0.1:48172 127.0.0.1:9090 ESTABLISHED
9086/./test_client
tcp 0 0 127.0.0.1:9090 127.0.0.1:48174 ESTABLISHED -
tcp 0 0 127.0.0.1:9090 127.0.0.1:48172 ESTABLISHED -这是因为, Linux内核协议栈为一个tcp连接管理使用两个队列


边栏推荐
- 基于QWebassembly的一个数据库监测工具
- Implementation of FIR filter based on FPGA (1) - using fir1 function design
- HackTheBox | Horizontall
- 京东三面惨遭被虐,关于redis,高并发,分布式,问懵了
- Using Flask and Celery to push real-time/timed messages asynchronously in Win10 environment (Socket.io)/The latest strategy in 2020
- poj2096 Collecting Bugs
- Tsinghua | GLM-130B: An Open Bilingual Pre-training Model
- PC端实用软件推荐
- 浅学一下二叉树链式存储结构的遍历
- Time to update your tech arsenal in 2020: Asgi vs Wsgi (FastAPI vs Flask)
猜你喜欢

The use of string function, character function, memory function and its analog implementation

优刻得“失速”:营收转降,定向增发股东浮亏超三成

Verilog HDL Bits training 09 grammar foundation

连锁小酒馆第一股,海伦司能否梦圆大排档?

KMP Media Group South Africa implemented a DMS (Document Management System) to digitize the process, employees can again focus on their actual tasks, providing efficiency

你是什么时候对深度学习失去信心的?

华谊“在劫难逃”,4年亏掉64亿

【系统设计】S3 对象存储

干货满满,中科院信工所于静新课帮你get学术研究与论文写作技能

“自降估值”3个亿的咖啡独角兽要IPO了
随机推荐
R语言ggplot2可视化:基于aes函数中的fill参数和shape参数自定义绘制分组折线图并添加数据点(散点)、设置可视化图像的主题为theme_gray
SAP数据迁移需要多久?
poj2096 Collecting Bugs
客户案例 | 提高银行信用卡客户贡献率
全网最全的AItium Designer 16下载资源与安装步骤
树上距离为1子集修改
又一个千亿市场,冰淇淋也成了创新试验田
【索引】图神经论文之GCN(持更)
Kotlin系列之let、with、run、apply、also函数的使用
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化堆叠的柱状图(stacked bar plot)、palette参数自定义不同水平柱状图边框以及填充的颜色
今日睡眠质量记录83分
【Redis】redis安装与客户端redis-cli的使用(批量操作)
AfterEffect插件-图层排序-js脚本开发-AE插件
[Redis] Redis installation and use of client redis-cli (batch operation)
[Redis] Bitmap and usage scenarios of bitmap (statistics of online people and user online status)
[C language] In-depth analysis of data storage in memory
flutter 身兼数职的getx —— 简介
【个人总结】2022.8.7周结
MySQL:索引(1)原理与底层结构
Qt的简易日志库实现及封装