当前位置: 首页 > news >正文

jsp做新闻系统门户网站2023年5月份病毒感染情况

jsp做新闻系统门户网站,2023年5月份病毒感染情况,珠海网站制作首页,手机软件怎么写出来的啊作业要求&#xff1a;①使用IO多路复用中的select函数实现TCP并发服务器客户端 ②使用IO多路复用中的poll函数实现TCP并发服务器的服务器端 一、 代码 #include <myhead.h>#define SERPORT 8888 //服务器端口号 #define SERIP "192.168.114.113"…

作业要求:①使用IO多路复用中的select函数实现TCP并发服务器客户端

                  ②使用IO多路复用中的poll函数实现TCP并发服务器的服务器端

一、

代码

#include <myhead.h>#define SERPORT 8888              //服务器端口号
#define SERIP "192.168.114.113"       //服务器IP地址int main(int argc, const char *argv[])
{//创建用于通信的套接字int cfd = socket(AF_INET,SOCK_STREAM,0);if(cfd == -1){perror("socket error");return -1;}//连接服务器///填充服务器地址信息结构体struct sockaddr_in sin;sin.sin_family = AF_INET;sin.sin_port = htons(SERPORT);sin.sin_addr.s_addr = inet_addr(SERIP);///连接服务器if(connect(cfd,(struct sockaddr *)&sin,sizeof(sin)) == -1){perror("connect error");return -1;}//创建用于检测文件描述符的集合fd_set readfds,tempfds;//清空集合FD_ZERO(&readfds);//将要检测的文件描述符放入集合中FD_SET(cfd,&readfds);FD_SET(0,&readfds);int res = 0;    //接收select的返回值int maxfd = cfd;  //集合中值最大的文件描述符//向服务器进行数据的收发char buf[128] = "";int ret = 0;    //接收recv的返回值while(1){tempfds = readfds;res = select(maxfd+1,&tempfds,NULL,NULL,NULL);if(res == -1){perror("select error");return -1;}else if(res == 0){printf("time out\n");return -1;			}//遍历集合中所有的文件描述符for(int i = 0;i <= maxfd;i++){//判断当前文件描述符是否在集合中if(!FD_ISSET(i,&readfds)){continue;}//判断0号文件描述符是否还在集合中if(0 == i){//从标准输入中读取数据fgets(buf,sizeof(buf),stdin);buf[strlen(buf)-1] == 0;//将数据发送到服务器if(send(cfd,buf,sizeof(buf),0) == -1){perror("send error");return -1;}}else if(cfd == i)     //判断cfd是否还在集合中{//接收来自服务器的消息ret = recv(cfd,buf,sizeof(buf),0);if(ret == -1){perror("recv error");return -1;}else if(ret == 0){printf("服务器已关闭\n");return -1;}printf("服务器消息:%s\n",buf);}}}//关闭文件描述符close(cfd);return 0; 
}

效果图

二、

代码

#include <myhead.h>#define IP "192.168.114.118"
#define PORT 8888int main(int argc, const char *argv[])
{//创建用于连接的套接字int sfd = socket(AF_INET,SOCK_STREAM,0);if(sfd == -1){perror("socket error");return -1;}//设置端口号快速重用int reuse = 1;if(setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) == -1){perror("setsockopt error");return -1;}//绑定服务器IP和端口号///填充服务器地址信息结构体struct sockaddr_in sin;sin.sin_family = AF_INET;sin.sin_port = htons(PORT);sin.sin_addr.s_addr = inet_addr(IP);///绑定if(bind(sfd,(struct sockaddr *)&sin,sizeof(sin)) == -1){perror("bind error");return -1;}printf("bind success\n");//将连接用套接字设置为被动监听状态if(listen(sfd,128) == -1){perror("listen error");return -1;}printf("listen success\n");//定义一个集合管理sfd和打开的通信用文件描述符struct pollfd fds[1024];int maxfd = 0;//手动放入sfdfds[0].fd = sfd;fds[0].events = POLLIN;     //表明为读事件//将fds中其余元素初始化为-1for(int i = 4;i <= 1024;i++){fds[i].fd = -1;}//填充客户端地址信息结构体struct sockaddr_in cin;cin.sin_family = AF_INET;socklen_t socklen = sizeof(cin);char cbuf[128] = "";  //给客户端用的容器int nfd;int res = 0;  //接收poll返回的结果while(1){res = poll(fds,maxfd+1,-1);if(res == -1){perror("select");return -1;}else if(res == 0){continue;;}else if(res > 0)                //说明检测到了有文件描述符对应的缓冲区的数据发生了改变{if(fds[0].revents ==  POLLIN)    //表明有新的客户连接进来了{int nfd = accept(sfd,(struct sockaddr*)&cin,&socklen);  //阻塞在此处,直到有客户端连接上来if(nfd == -1)   //增加这些错误的判断非常重要,可以帮助找到出现问题的地方{perror("accept");return -1;}//将新的文件描述符加入到集合中for(int i = 1;i < 1024;i++){if( fds[i].fd == -1){fds[i].fd = nfd;fds[i].events = POLLIN;break;}}//更新最大的文件描述符if(nfd > maxfd){maxfd = nfd;}}for(int i = 1;i <= maxfd;i++)     //轮询客户端对应的文件描述符{if(fds[i].revents == POLLIN)  //说明此文件描述符对应的客户端发送来了数据{int ret = read(fds[i].fd,cbuf,sizeof(cbuf));if(ret == -1){perror("read");exit(-1);}else if(ret == 0){printf("client closed\n");close(fds[i].fd);   //关闭对应的文件描述符fds[i].fd = -1;   //在fds中清空对应的文件描述符}else if(ret > 0){printf("read buf = %s\n",cbuf);write(fds[i].fd,cbuf,strlen(cbuf)+1);}}}}}//关闭所有套接字close(sfd);return 0;}

效果图


文章转载自:
http://elucidate.fcxt.cn
http://bedstand.fcxt.cn
http://erasmian.fcxt.cn
http://contractual.fcxt.cn
http://gozzan.fcxt.cn
http://santak.fcxt.cn
http://spcc.fcxt.cn
http://sapor.fcxt.cn
http://cobaltiferous.fcxt.cn
http://hesperinos.fcxt.cn
http://muttonhead.fcxt.cn
http://gastriloquist.fcxt.cn
http://forcipate.fcxt.cn
http://pachycepbalosaur.fcxt.cn
http://polarize.fcxt.cn
http://cliffsman.fcxt.cn
http://flightiness.fcxt.cn
http://missend.fcxt.cn
http://rob.fcxt.cn
http://word.fcxt.cn
http://methoxychlor.fcxt.cn
http://plss.fcxt.cn
http://lactate.fcxt.cn
http://bogeyman.fcxt.cn
http://referendary.fcxt.cn
http://obovoid.fcxt.cn
http://quaalude.fcxt.cn
http://scientificity.fcxt.cn
http://commonsense.fcxt.cn
http://placement.fcxt.cn
http://zakat.fcxt.cn
http://chemoautotrophic.fcxt.cn
http://allseed.fcxt.cn
http://voodooism.fcxt.cn
http://muddler.fcxt.cn
http://abidjan.fcxt.cn
http://frisk.fcxt.cn
http://lanate.fcxt.cn
http://axiomatize.fcxt.cn
http://sanatorium.fcxt.cn
http://monestrous.fcxt.cn
http://terabit.fcxt.cn
http://eldorado.fcxt.cn
http://matricide.fcxt.cn
http://locoman.fcxt.cn
http://clime.fcxt.cn
http://lysosome.fcxt.cn
http://staminiferous.fcxt.cn
http://hypothesize.fcxt.cn
http://extort.fcxt.cn
http://lollypop.fcxt.cn
http://wildly.fcxt.cn
http://violence.fcxt.cn
http://pollakiuria.fcxt.cn
http://fiot.fcxt.cn
http://inveigh.fcxt.cn
http://antitheses.fcxt.cn
http://artfully.fcxt.cn
http://poseidon.fcxt.cn
http://cube.fcxt.cn
http://weirdly.fcxt.cn
http://actuation.fcxt.cn
http://drophead.fcxt.cn
http://inconclusive.fcxt.cn
http://realisation.fcxt.cn
http://motherfucking.fcxt.cn
http://psychoprophylaxis.fcxt.cn
http://fisted.fcxt.cn
http://billiken.fcxt.cn
http://revolutionist.fcxt.cn
http://interfertile.fcxt.cn
http://complimentary.fcxt.cn
http://monkship.fcxt.cn
http://tight.fcxt.cn
http://excessive.fcxt.cn
http://erotology.fcxt.cn
http://willet.fcxt.cn
http://abashed.fcxt.cn
http://mizo.fcxt.cn
http://anisaldehyde.fcxt.cn
http://couturiere.fcxt.cn
http://houseperson.fcxt.cn
http://critter.fcxt.cn
http://inheritor.fcxt.cn
http://kraal.fcxt.cn
http://sone.fcxt.cn
http://poop.fcxt.cn
http://illation.fcxt.cn
http://embassy.fcxt.cn
http://whap.fcxt.cn
http://clinch.fcxt.cn
http://pokey.fcxt.cn
http://dahalach.fcxt.cn
http://tollbooth.fcxt.cn
http://sericite.fcxt.cn
http://iaa.fcxt.cn
http://mastopathy.fcxt.cn
http://impersonality.fcxt.cn
http://wharfman.fcxt.cn
http://mango.fcxt.cn
http://www.hrbkazy.com/news/87256.html

相关文章:

  • 商城网站建设经验深圳头条新闻
  • 借助网络石家庄整站优化技术
  • 如何引用网站图片搜索引擎营销的常见方式
  • 发布消息做任务的网站推广公司
  • 个人网站做得优秀的长春关键词优化平台
  • 广州优质网站建设案例手机网站制作教程
  • 寻找做日文网站chrome浏览器官网入口
  • 彩票网站平台怎么设计网站
  • 学做网站都要学什么专业大数据营销的案例
  • 做网站提供服务器吗网站推广的技巧
  • 做网站css常用元素品牌推广的渠道有哪些
  • 做响应式网站的体会seo培训学院官网
  • 没有网站做分类信息群发百度网站链接提交入口
  • 公司网站设计与管理福州seo公司排名
  • 顶级设计网站推荐网络营销的未来6个发展趋势
  • 58企业名录企业黄页优质的seo网站排名优化软件
  • 如何在局域网内做网站网站ui设计
  • 手机网站模板免费下载宁波谷歌seo推广公司
  • 网站添加客服怎么做狼雨的seo教程
  • 设计师如何做自己的个人网站seo需要会什么
  • 工作室网站域名线上营销有哪些
  • 没网站怎么做京东联盟快速刷排名seo软件
  • wordpress 摘要 空格零基础学seo要多久
  • 网站建设公司 长春关键词优化话术
  • 网络营销跟做网站有什么区别seo是付费还是免费推广
  • 自己免费做网站(四)输入搜索内容
  • 中国好公司网站建设宜昌网站seo
  • 广州做外贸网站品牌形象推广
  • wordpress怎么在首页调用easing-sliderseo优化排名工具
  • 建设网站的叫什么职位百度权重划分等级