演示结果:
示例代码:
//
// Created by linux on 2021/2/5.
//
#include <iostream>
#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
using namespace std;
int main(int argc,char* argv[])
{
cout<<"linux select网络模型演示"<<endl;
//变量声明
int i=0;//客户端连接索引
int nready=0;
int maxi=-1;
unsigned short port = 8000;//服务监听端口
int maxListen = FD_SETSIZE;//客户端最大连接数量
//创建socket
int socket_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (socket_fd<0)
{
cout<<"创建sock