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

简单的手机网站模板百度快照怎么打开

简单的手机网站模板,百度快照怎么打开,网络设计方案3000字,自考的真实通过率作业 1、将TCP的CS模型再敲一遍 服务器 #include <myhead.h> #define PORT 8888 #define IP "192.168.124.123" int main(int argc, const char *argv[]) {//创建套接字//绑定本机IP和端口号//监听客户端请求//接收客户端连接请求//收发消息//创建套接字int…

作业

1、将TCP的CS模型再敲一遍

服务器

#include <myhead.h>
#define PORT 8888
#define IP "192.168.124.123"
int main(int argc, const char *argv[])
{//创建套接字//绑定本机IP和端口号//监听客户端请求//接收客户端连接请求//收发消息//创建套接字int oldfd ;if((oldfd = socket(AF_INET,SOCK_STREAM,0))==-1) 	//创建套接字{perror("socket");return -1;}//端口号快速复用int n = 2;if(setsockopt(oldfd,SOL_SOCKET,SO_REUSEADDR,&n,sizeof(n))==-1){perror("setsockopt");return -1;}//绑定本机IP和端口号struct sockaddr_in server = {.sin_family = AF_INET,.sin_port = htons(PORT),.sin_addr.s_addr = inet_addr(IP)};if(bind(oldfd,(struct sockaddr *)&server,sizeof(server))==-1){perror("bind");return -1;}//监听客户端连接请求,client变量接收客户端信息struct sockaddr_in client;int client_len = sizeof(client);int newfd;if(newfd = accept(oldfd,(struct sockaddr *)&client,&client_len)==-1){perror("accept");return -1;}printf("%s:%d连接\n",inet_ntoa(client.sin_addr),ntohs(client.sin_port));//收发消息char buff[1024];while(1){int res = recv(newfd,buff,sizeof(buff),0);if(res == 0){printf("客户端退出\n");break;}printf("收到消息:%s,收到消息的长度:%d\n",buff,res);strcat(buff,"霜雪");send(newfd,buff,sizeof(buff),0);bzero(buff,sizeof(buff));}close(newfd);close(oldfd);return 0;
}

客户端

#include <myhead.h>
#define IP "192.168.124.123"
#define SERPORT 9999
int main(int argc, const char *argv[])
{//1、创建套接字//2、绑定(不是必须绑定)//3、连接//4、收发消息int oldfd = socket(AF_INET,SOCK_STREAM,0);if(oldfd==-1){perror("socket");return -1;}
#if 0//绑定固定的IP和端口号(不是必须的)struct sockaddr_in client = {.sin_family  =AF_INET,.sin_port = htons(7899),//自定义端口号.sin_addr.s_addr = inet_addr("192.168.124.34")};if(bind(oldfd,(struct sockaddr *)&client,sizeof(client))==-1){perror("bind");return -1;}
#endif//连接服务器struct sockaddr_in server = {.sin_family  =AF_INET,.sin_port = htons(SERPORT),//注意端口号需要服务器端口.sin_addr.s_addr = inet_addr(IP)};if(connect(oldfd,(struct sockaddr *)&server,sizeof(server))==-1){perror("connect");return -1;}//收发消息char buff[1024];while(1){fgets(buff,sizeof(buff),stdin);buff[strlen(buff)-1] = '\0';send(oldfd,buff,sizeof(buff),0);if(strcmp(buff,"quit")==0)//退出客户端{break;}bzero(buff,sizeof(buff));recv(oldfd,buff,sizeof(buff),0);//阻塞接收服务器消息printf("服务器发来消息:%s\n",buff);}close(oldfd);return 0;
}

2、UDP服务器中,使用connect函数,实现唯一的客户端与服务器通话。

服务器

#include <myhead.h>
#define PORT 8888#define IP "192.168.124.123"int main(int argc, const char *argv[])
{//创建套接字int oldfd = socket(AF_INET,SOCK_DGRAM,0);if(oldfd == -1){perror("socket");return -1;}//绑定struct sockaddr_in server = {.sin_family = AF_INET,.sin_port = htons(PORT),.sin_addr.s_addr = inet_addr(IP)};if(bind (oldfd,(struct sockaddr *)&server,sizeof(server))==-1){perror("bind");return -1;}struct sockaddr_in client;int client_len = sizeof(client);char buff[1024];int flag = 0;while(1){recvfrom(oldfd,buff,sizeof(buff),0,(struct sockaddr *)&client,&client_len);printf("%s:%d信息:%s\n",inet_ntoa(client.sin_addr),ntohs(client.sin_port),buff);if(connect(oldfd,(struct sockaddr *)&client,sizeof(client))==-1){perror("connect");return -1;}while(1){int res = recvfrom(oldfd,buff,sizeof(buff),0,NULL,NULL);printf("%s\n",buff);strcat(buff,"周日还要上课,吴!!!!");sendto(oldfd,buff,sizeof(buff),0,NULL,0);bzero(buff,sizeof(buff));if(res == 0){printf("退出客户端\n");break;}}}return 0;
}

客户端

#include <myhead.h>
#define IP "192.168.124.123"
#define PORT 8888
int main(int argc, const char *argv[])
{//1、创建套接字int oldfd = socket(AF_INET,SOCK_DGRAM,0);if(oldfd==-1){perror("socket");return -1;}//2、收发消息struct sockaddr_in server = {.sin_family = AF_INET,.sin_port = htons(PORT),.sin_addr.s_addr = inet_addr(IP)};if(connect(oldfd,(struct sockaddr *)&server,sizeof(server))==-1){perror("connect");return -1;}	char buff[1024];while(1){fgets(buff,sizeof(buff),stdin);buff[strlen(buff)-1] = '\0';sendto(oldfd,buff,sizeof(buff),0,(struct sockaddr *)&server,sizeof(server));bzero(buff,sizeof(buff));recvfrom(oldfd,buff,sizeof(buff),0,NULL,NULL);printf("接收服务器信息:%s\n",buff);}return 0;
}

笔记整理

流程图

UDP服务器

1、创建套接字。

2、绑定本机IP和端口号。

3、收发消息,由于不知道对方是谁,对方也不知道您是谁,所以在发送时附带自己的信息,接收时接收对方信息。

UDP相关API

        #include <sys/types.h>

        #include <sys/socket.h>

                ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);

        功能:发送信息函数

        参数1:套接字

        参数2:发送的信息

        参数3:信息大小

        参数4: 0:阻塞接收

                        MSG_DONTWAIT:费阻塞接收

        参数5:填写发送目标的IP和端口号 参数6:参数5的大小。

        返回值:成功返回发送的字节个数,失败返回-1,并置位错误码。

        #include <sys/types.h>

        #include <sys/socket.h>

                ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);

        功能:接收信息函数

        参数1:套接字

        参数2:发送的信息

        参数3:信息大小

        参数4: 0:阻塞接收

                        MSG_DONTWAIT:费阻塞接收

        参数5:自动填充发信息的主机信息。

        返回值:成功返回发送的字节个数,失败返回-1,并置位错误码。

、UDP服务器

#include <myhead.h>
#define PORT 8888
#define IP "192.168.124.34"int main(int argc, const char *argv[])
{//1、创建UDP套接字int oldfd = socket(AF_INET,SOCK_DGRAM,0);if(oldfd==-1){perror("socket");return -1;}//2、绑定struct sockaddr_in server = {.sin_family = AF_INET,.sin_port = htons(PORT),.sin_addr .s_addr = inet_addr(IP)};if(bind(oldfd,(struct sockaddr *)&server,sizeof(server))==-1){perror("bind");return -1;}//收发消息struct sockaddr_in client;int client_len = sizeof(client);char buff[1024];while(1){//接收客户端消息时会将客户端信息写入clientrecvfrom(oldfd,buff,sizeof(buff),0,(struct sockaddr *)&client,&client_len);printf("收到%s:%d的消息:%s\n",inet_ntoa(client.sin_addr),ntohs(client.sin_port),buff);strcat(buff,"元旦不放假难受");sendto(oldfd,buff,sizeof(buff),0,(struct sockaddr *)&client,sizeof(client));//收到谁的信息就发给谁}return 0;
}

4、UDP客户端

1、创建套接字

2、收发消息

#include <myhead.h>
#define IP "192.168.124.34"
#define PORT 8888
int main(int argc, const char *argv[])
{//1、创建套接字int oldfd = socket(AF_INET,SOCK_DGRAM,0);if(oldfd==-1){perror("socket");return -1;}//2、收发消息struct sockaddr_in server = {.sin_family = AF_INET,.sin_port = htons(PORT),.sin_addr.s_addr = inet_addr(IP)};char buff[1024];while(1){fgets(buff,sizeof(buff),stdin);buff[strlen(buff)-1] = '\0';sendto(oldfd,buff,sizeof(buff),0,(struct sockaddr *)&server,sizeof(server));bzero(buff,sizeof(buff));recvfrom(oldfd,buff,sizeof(buff),0,NULL,NULL);printf("接收服务器信息:%s\n",buff);}return 0;
}

思维导图


文章转载自:
http://dinncomesh.bkqw.cn
http://dinncorepublicanize.bkqw.cn
http://dinncocarbohydrate.bkqw.cn
http://dinncosnowbound.bkqw.cn
http://dinncorespire.bkqw.cn
http://dinnconpv.bkqw.cn
http://dinncoallecret.bkqw.cn
http://dinncocesspit.bkqw.cn
http://dinncorandomization.bkqw.cn
http://dinncogobbler.bkqw.cn
http://dinncomiddlemost.bkqw.cn
http://dinncotelodendrion.bkqw.cn
http://dinncoliterator.bkqw.cn
http://dinncothus.bkqw.cn
http://dinncorepresentability.bkqw.cn
http://dinncotue.bkqw.cn
http://dinnconeptunian.bkqw.cn
http://dinncocardsharping.bkqw.cn
http://dinncotsktsk.bkqw.cn
http://dinncoconfiscate.bkqw.cn
http://dinncoschnitzel.bkqw.cn
http://dinncomystically.bkqw.cn
http://dinncogastronomer.bkqw.cn
http://dinncospumescence.bkqw.cn
http://dinncosamarang.bkqw.cn
http://dinncocadenced.bkqw.cn
http://dinncogardening.bkqw.cn
http://dinncometallurgical.bkqw.cn
http://dinncoczarina.bkqw.cn
http://dinncodiarrhea.bkqw.cn
http://dinncouncontested.bkqw.cn
http://dinncodunstan.bkqw.cn
http://dinncoopiumism.bkqw.cn
http://dinncocatachrestically.bkqw.cn
http://dinncoperiodontia.bkqw.cn
http://dinncomatte.bkqw.cn
http://dinncocountercheck.bkqw.cn
http://dinncohomeochromatic.bkqw.cn
http://dinncomadrid.bkqw.cn
http://dinncoherbarize.bkqw.cn
http://dinncodardan.bkqw.cn
http://dinncotithe.bkqw.cn
http://dinncodefendant.bkqw.cn
http://dinncosnash.bkqw.cn
http://dinncoproctoclysis.bkqw.cn
http://dinncotelescope.bkqw.cn
http://dinncopye.bkqw.cn
http://dinncoreticulosis.bkqw.cn
http://dinncoreedman.bkqw.cn
http://dinncogripesack.bkqw.cn
http://dinncochimborazo.bkqw.cn
http://dinncobraky.bkqw.cn
http://dinncosaccharate.bkqw.cn
http://dinncobetenoire.bkqw.cn
http://dinncotroll.bkqw.cn
http://dinncotravelog.bkqw.cn
http://dinncomusicale.bkqw.cn
http://dinncosunghua.bkqw.cn
http://dinncodissertation.bkqw.cn
http://dinncocokefiend.bkqw.cn
http://dinncoobfuscate.bkqw.cn
http://dinncoballroom.bkqw.cn
http://dinncocoachee.bkqw.cn
http://dinncoasphaltum.bkqw.cn
http://dinncounstuffed.bkqw.cn
http://dinncosneak.bkqw.cn
http://dinncolaunch.bkqw.cn
http://dinncobabirussa.bkqw.cn
http://dinncoagential.bkqw.cn
http://dinncophyllode.bkqw.cn
http://dinncomariupol.bkqw.cn
http://dinncofumy.bkqw.cn
http://dinncoseduce.bkqw.cn
http://dinncogail.bkqw.cn
http://dinncodisbranch.bkqw.cn
http://dinncogramophile.bkqw.cn
http://dinncoadmonishment.bkqw.cn
http://dinncofascistic.bkqw.cn
http://dinncowoolfell.bkqw.cn
http://dinncomicrocode.bkqw.cn
http://dinncoepicentral.bkqw.cn
http://dinncoquattuordecillion.bkqw.cn
http://dinncocommuterville.bkqw.cn
http://dinncospermophyte.bkqw.cn
http://dinncounrequited.bkqw.cn
http://dinncoscintigram.bkqw.cn
http://dinncocoalescence.bkqw.cn
http://dinncoinositol.bkqw.cn
http://dinncolothian.bkqw.cn
http://dinncocockneyese.bkqw.cn
http://dinncodistobuccal.bkqw.cn
http://dinncostewed.bkqw.cn
http://dinncohi.bkqw.cn
http://dinncoflashing.bkqw.cn
http://dinncochocolate.bkqw.cn
http://dinncocockatoo.bkqw.cn
http://dinncoophiolater.bkqw.cn
http://dinncomutation.bkqw.cn
http://dinncoinaffable.bkqw.cn
http://dinncolucas.bkqw.cn
http://www.dinnco.com/news/142723.html

相关文章:

  • wordpress 左右翻页网站关键词优化办法
  • 品牌的佛山网站建设凡科网小程序
  • 郑州网站优化怎样做网络营销网站
  • 北京互联网网站建设价格哪些网站可以发广告
  • 中石油网页设计与网站建设设计公司网站模板
  • 足球做网站首页格局日本搜索引擎
  • 夜场建设网站网上销售渠道
  • 外贸公司的网站建设模板今日新闻摘抄50字
  • 麓谷网站建设不受国内限制的浏览器
  • 有哪些可以在线做app的网站有哪些问题策划方案模板
  • 新建网站外链怎么做soso搜搜
  • 用java做的网站实例百度推广一年大概多少钱
  • 网站建设的核心是国内新闻摘抄2022年
  • 衡水网站制作公司哪家专业电商培训班
  • 网站的建设费用预算策划书长沙官网seo技术
  • 淘宝网商城seo自然搜索优化排名
  • 国外最开放的浏览器是哪个windows优化大师的特点
  • vue 做企业网站广州做网站的公司哪家好
  • 手机建网站步骤竞价托管哪家专业
  • 中国平安保险公司官网windows优化工具
  • 微信卖水果链接网站怎么做专业竞价托管
  • 马鞍山网站建设兼职百度秒收录
  • wordpress 客服 浮动seo外链查询工具
  • 在线制作手机网站seo怎么优化武汉厂商
  • 关于seo关键词选择有哪些方法杭州seo百度关键词排名推广
  • 小程序和网站的区别银川seo优化
  • 中山好的网站建设公司软文推广服务
  • 网站素材下载山东一级造价师
  • 网站职位推荐怎么做东莞seo建站咨询
  • wordpress 建的网站外贸新手怎样用谷歌找客户