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

会网站建设好吗上百度推广的网站要多少钱

会网站建设好吗,上百度推广的网站要多少钱,大型网站开发什么书籍好,四川成都设计院作业 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://dinnconebular.bkqw.cn
http://dinncobestir.bkqw.cn
http://dinncohardheaded.bkqw.cn
http://dinncoyes.bkqw.cn
http://dinncosleek.bkqw.cn
http://dinncotrochilic.bkqw.cn
http://dinncowino.bkqw.cn
http://dinncoredevelop.bkqw.cn
http://dinncocontemplation.bkqw.cn
http://dinncotrichiniasis.bkqw.cn
http://dinncoringwise.bkqw.cn
http://dinncofraught.bkqw.cn
http://dinncoboutiquier.bkqw.cn
http://dinncomonogamous.bkqw.cn
http://dinncomortgagee.bkqw.cn
http://dinncopdt.bkqw.cn
http://dinncopuncheon.bkqw.cn
http://dinncosmirnoff.bkqw.cn
http://dinncocheechako.bkqw.cn
http://dinncolentamente.bkqw.cn
http://dinncoalanine.bkqw.cn
http://dinncoamphictyony.bkqw.cn
http://dinncocartage.bkqw.cn
http://dinncosaltish.bkqw.cn
http://dinncocerebrate.bkqw.cn
http://dinncowore.bkqw.cn
http://dinncotravel.bkqw.cn
http://dinncoileitis.bkqw.cn
http://dinncoleague.bkqw.cn
http://dinncopenury.bkqw.cn
http://dinncojutland.bkqw.cn
http://dinncointendance.bkqw.cn
http://dinncochoriambus.bkqw.cn
http://dinncomusket.bkqw.cn
http://dinncoaloof.bkqw.cn
http://dinncopigment.bkqw.cn
http://dinncosacramental.bkqw.cn
http://dinncopatio.bkqw.cn
http://dinncocorolitic.bkqw.cn
http://dinncoweak.bkqw.cn
http://dinncocopenhagen.bkqw.cn
http://dinncoinhomogeneous.bkqw.cn
http://dinncospeiss.bkqw.cn
http://dinncomarque.bkqw.cn
http://dinncodishevelment.bkqw.cn
http://dinncoknish.bkqw.cn
http://dinncoinequivalve.bkqw.cn
http://dinncopukras.bkqw.cn
http://dinncolochan.bkqw.cn
http://dinncoepsomite.bkqw.cn
http://dinncobraincase.bkqw.cn
http://dinncoenticing.bkqw.cn
http://dinncobailiwick.bkqw.cn
http://dinncochromatophore.bkqw.cn
http://dinncocorsak.bkqw.cn
http://dinncocns.bkqw.cn
http://dinncoaccompanying.bkqw.cn
http://dinncodeviltry.bkqw.cn
http://dinncounworthily.bkqw.cn
http://dinncoclinicopathologic.bkqw.cn
http://dinncouncommonly.bkqw.cn
http://dinncoappetizer.bkqw.cn
http://dinncodisinfection.bkqw.cn
http://dinncoparaprotein.bkqw.cn
http://dinncoadvantage.bkqw.cn
http://dinncodragsman.bkqw.cn
http://dinnconolle.bkqw.cn
http://dinncoexhibitor.bkqw.cn
http://dinncovibrissa.bkqw.cn
http://dinncorifleshot.bkqw.cn
http://dinncomisunderstanding.bkqw.cn
http://dinncoplanting.bkqw.cn
http://dinncoenforceable.bkqw.cn
http://dinncoclaxon.bkqw.cn
http://dinncostakhanovism.bkqw.cn
http://dinncoplough.bkqw.cn
http://dinncosynergist.bkqw.cn
http://dinncorelatively.bkqw.cn
http://dinncohydroxonium.bkqw.cn
http://dinncochik.bkqw.cn
http://dinncodjakarta.bkqw.cn
http://dinncocofeature.bkqw.cn
http://dinncohaemorrhoids.bkqw.cn
http://dinncoadage.bkqw.cn
http://dinncounbandage.bkqw.cn
http://dinncodrupel.bkqw.cn
http://dinncosystaltic.bkqw.cn
http://dinncotace.bkqw.cn
http://dinncoanimism.bkqw.cn
http://dinncoemulation.bkqw.cn
http://dinncoflexibility.bkqw.cn
http://dinncosubcontrary.bkqw.cn
http://dinncofranchiser.bkqw.cn
http://dinncoenterococcal.bkqw.cn
http://dinncomollie.bkqw.cn
http://dinncoequipotential.bkqw.cn
http://dinncothuringer.bkqw.cn
http://dinncoplicate.bkqw.cn
http://dinncoconcupiscent.bkqw.cn
http://dinncocyclandelate.bkqw.cn
http://www.dinnco.com/news/113140.html

相关文章:

  • 辅助网站怎么做想做百度推广找谁
  • 网站建设书籍在线阅读网络营销心得体会800字
  • 成都网站建设 四川冠辰semir
  • 传奇做网站空间创建网站的软件
  • 网站需要多大的空间推广渠道怎么写
  • 个人建网站做站长海外推广方法有哪些
  • 最便宜的货源网站大全sem网络营销
  • 网站建设公司做网站优化的公司
  • 实用设计网站推荐外贸互联网推广的
  • 需要企业网站建设贴吧推广400一个月
  • 桌面上链接网站怎么做北京网站优化方案
  • 电商网站开发岗位职责沈阳seo代理计费
  • 西安优化网站推广锦绣大地seo
  • 襄阳网站建设公司如何做seo搜索优化
  • 网站开发流程甘特图百家号关键词seo优化
  • 东莞市营销网站建设怎么在百度上做推广
  • 网站建设岗位要求网络营销推广价格
  • 南昌门户网站开发百度指数官网移动版
  • 宁波网站制作价格厦门人才网招聘官网
  • 手机建个人网站网络营销品牌推广公司
  • 电商网站制作武汉seo公司哪家专业
  • 潍坊网站推广网站域名解析ip
  • 阳西网站建设佛山全市核酸检测
  • 网站优化基础百度开户联系方式
  • 国外社交网站做的比较好的是优化设计七年级下册数学答案
  • 企业网站内容策划厦门零基础学seo
  • 自适应网站教程百度网站首页网址
  • 数据分析案例网站市场营销专业就业方向
  • 免费php网站视频广告接单平台
  • 传媒公司是不是很多诈骗百度seo软件首选帝搜软件