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

凡科网的网站建设怎么做关键词歌词简谱

凡科网的网站建设怎么做,关键词歌词简谱,网站全屏图片怎么做,综合b2b网站有哪些1.广播 发送端&#xff08;类似于客户端&#xff09; 流程&#xff1a; 创建套接字 填充接收端&#xff08;服务器&#xff09;网络信息结构体 bind(非必须绑定) 设置允许广播 向接收端&#xff08;服务器&#xff09;发送数据 关闭套接字文件 #include <stdio.h> #in…

1.广播

发送端(类似于客户端)

流程:
创建套接字
填充接收端(服务器)网络信息结构体
bind(非必须绑定)
设置允许广播
向接收端(服务器)发送数据
关闭套接字文件

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>#define ERR_MSG(msg) do{\fprintf(stderr,"LINE:__%d__",__LINE__);\perror(msg);\
}while(0)#define PORT 3333
#define IP "172.17,94.255"int main(int argc, const char *argv[])
{int fd = socket(AF_INET,SOCK_DGRAM,0);if(-1 == fd){ERR_MSG("socket");return -1;}//填充接受端的网络信息结构体struct sockaddr_in recvaddr;recvaddr.sin_family = AF_INET;recvaddr.sin_port   = htons(PORT);recvaddr.sin_addr.s_addr = inet_addr(IP);//bind可绑可不绑//设置允许广播int broad = 1;if(-1 == setsockopt(fd,SOL_SOCKET,SO_BROADCAST,\&broad,sizeof(broad))){ERR_MSG("setsockopt");return -1;}printf("broad set success broad = %d\n",broad);char buf[128] = "";ssize_t res = 0;while(1){//向服务器发送数据bzero(buf,sizeof(buf));fgets(buf,sizeof(buf),stdin);buf[strlen(buf)-1] = 0;if(-1 == sendto(fd,buf,sizeof(buf),0,\(struct sockaddr*)&recvaddr,sizeof(recvaddr))){ERR_MSG("sendto");return -1;}printf("sendto success\n");}//关闭套接字close(fd);return 0;
}

接收端(类似于服务器)

流程:
创建套接字
填充接收端(本身)(服务器)的网络信息结构体
bind(必须) 绑定套接字和自身的网络信息结构体
新建一个网络信息结构体,用来存储发送端的地址信息
接受发送端发来的数据
关闭套接字

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>#define ERR_MSG(msg) do{\fprintf(stderr,"LINE:__%d__",__LINE__);\perror(msg);\
}while(0)#define PORT 3333
#define IP "172.17,94.255"int main(int argc, const char *argv[])
{int fd = socket(AF_INET,SOCK_DGRAM,0);if(-1 == fd){ERR_MSG("socket");return -1;}//填充接受端的网络信息结构体struct sockaddr_in recvaddr;int len = sizeof(recvaddr);recvaddr.sin_family = AF_INET;recvaddr.sin_port   = htons(PORT);recvaddr.sin_addr.s_addr = inet_addr(IP);//必须绑定if(-1 == bind(fd,(struct sockaddr*)&recvaddr,len)){ERR_MSG("bind");return -1;}printf("bind success\n");//新建一个网络信息结构体,用来存储接受的数据从哪来struct sockaddr_in sendaddr;int sendlen = sizeof(sendaddr);char buf[128] = "";ssize_t res = 0;while(1){//接受发送端(客户端)发来的数据bzero(buf,sizeof(buf));if(-1 == recvfrom(fd,buf,sizeof(buf),0,\(struct sockaddr*)&sendaddr,&sendlen)){ERR_MSG("recvfrom");return -1;}printf("recvfrom success\n");printf("[%s:%d] msg:%s\n",inet_ntoa(sendaddr.sin_addr),\ntohs(sendaddr.sin_port),buf);}//关闭套接字close(fd);return 0;
}

广播

发送端(类似于客户端)

流程:
创建套接字
填充接收端(服务器)的网络信息结构体 (IP为广播组的IP地址)
bind(非必须)
设置允许广播
发送广播信息
关闭套接字

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>#define ERR_MSG(msg) do{\fprintf(stderr,"LINE:__%d__",__LINE__);\perror(msg);\
}while(0)#define PORT 3333
#define IP "224.1.2.3"int main(int argc, const char *argv[])
{int fd = socket(AF_INET,SOCK_DGRAM,0);if(-1 == fd){ERR_MSG("socket");return -1;}//填充接受端的网络信息结构体struct sockaddr_in recvaddr;recvaddr.sin_family = AF_INET;recvaddr.sin_port   = htons(PORT);recvaddr.sin_addr.s_addr = inet_addr(IP);//bind可绑可不绑//设置允许广播int broad = 1;if(-1 == setsockopt(fd,SOL_SOCKET,SO_BROADCAST,\&broad,sizeof(broad))){ERR_MSG("setsockopt");return -1;}printf("broad set success broad = %d\n",broad);char buf[128] = "";ssize_t res = 0;while(1){//向服务器发送数据bzero(buf,sizeof(buf));fgets(buf,sizeof(buf),stdin);buf[strlen(buf)-1] = 0;if(-1 == sendto(fd,buf,sizeof(buf),0,\(struct sockaddr*)&recvaddr,sizeof(recvaddr))){ERR_MSG("sendto");return -1;}printf("sendto success\n");}//关闭套接字close(fd);return 0;
}

接收端(类似于服务器)

流程:
创建套接字
填充接收端(自身、服务器)的网络信息结构体(广播组IP…)
bind(必须绑定)绑定服务器与套接字
填充广播组的网络信息结构体(广播组IP,本地IP,网卡编号)
滴滴:查询网卡编号:ifconfig 查看使用的是哪个网卡,再 ip ad 查看对应的编号
添加广播组
新建一个网络信息结构体用来存储发送端的地址信息
循环接受信息
关闭套接字

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>#define ERR_MSG(msg) do{\fprintf(stderr,"LINE:__%d__",__LINE__);\perror(msg);\
}while(0)#define PORT 3333
#define IP "224.1.2.3"int main(int argc, const char *argv[])
{int fd = socket(AF_INET,SOCK_DGRAM,0);if(-1 == fd){ERR_MSG("socket");return -1;}//填充接受端的网络信息结构体struct sockaddr_in recvaddr;int len = sizeof(recvaddr);recvaddr.sin_family = AF_INET;recvaddr.sin_port   = htons(PORT);recvaddr.sin_addr.s_addr = inet_addr(IP);//必须绑定if(-1 == bind(fd,(struct sockaddr*)&recvaddr,len)){ERR_MSG("bind");return -1;}printf("bind success\n");//加入多播组struct ip_mreqn mq;mq.imr_multiaddr.s_addr = inet_addr(IP);//多播组的组ipmq.imr_address.s_addr  = inet_addr("172.17.94.145");//本地IPmq.imr_ifindex   = 3;//网络设备编号,指定网卡号if(-1 == setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,\&mq,sizeof(mq))){ERR_MSG("setsockopt");return -1;}printf("membership set succes ");//新建一个网络信息结构体,用来存储接受的数据从哪来struct sockaddr_in sendaddr;int sendlen = sizeof(sendaddr);char buf[128] = "";ssize_t res = 0;while(1){//接受发送端(客户端)发来的数据bzero(buf,sizeof(buf));res = recvfrom(fd,buf,sizeof(buf),0,\(struct sockaddr*)&sendaddr,&sendlen);if(-1 == res){ERR_MSG("recvfrom");return -1;}else if(0 == res){printf("发送端退出\n");break;}printf("recvfrom success\n");printf("[%s:%d] msg:%s\n",inet_ntoa(sendaddr.sin_addr),\ntohs(sendaddr.sin_port),buf);}//关闭套接字close(fd);return 0;
}

结果:
在这里插入图片描述


文章转载自:
http://dinncokatydid.tpps.cn
http://dinnconormalizer.tpps.cn
http://dinncomaddeningly.tpps.cn
http://dinncogammadia.tpps.cn
http://dinncohelio.tpps.cn
http://dinncocounterthrust.tpps.cn
http://dinncoeulogium.tpps.cn
http://dinncoceremony.tpps.cn
http://dinncoparietal.tpps.cn
http://dinncofloridity.tpps.cn
http://dinncoappellant.tpps.cn
http://dinncodimethylmethane.tpps.cn
http://dinncoketene.tpps.cn
http://dinncounwarmed.tpps.cn
http://dinncosemiellipse.tpps.cn
http://dinncojangler.tpps.cn
http://dinncoscabies.tpps.cn
http://dinncodeterrence.tpps.cn
http://dinncobufalin.tpps.cn
http://dinncotaphephobia.tpps.cn
http://dinncogoner.tpps.cn
http://dinncosoftwood.tpps.cn
http://dinncophilistine.tpps.cn
http://dinncogay.tpps.cn
http://dinncoetherization.tpps.cn
http://dinncofremdness.tpps.cn
http://dinncocaruncle.tpps.cn
http://dinncoberberine.tpps.cn
http://dinncoisochromosome.tpps.cn
http://dinncoaeriform.tpps.cn
http://dinncorussianist.tpps.cn
http://dinncouraniferous.tpps.cn
http://dinncoesperanto.tpps.cn
http://dinnconihil.tpps.cn
http://dinncowarhead.tpps.cn
http://dinncoexecration.tpps.cn
http://dinncoopsin.tpps.cn
http://dinncoanthrosphere.tpps.cn
http://dinncoinforming.tpps.cn
http://dinncoseraglio.tpps.cn
http://dinncoterzetto.tpps.cn
http://dinncotransfigure.tpps.cn
http://dinncomonopolistic.tpps.cn
http://dinncoguthrun.tpps.cn
http://dinncodoze.tpps.cn
http://dinncopinky.tpps.cn
http://dinncocelibatarian.tpps.cn
http://dinncowaggery.tpps.cn
http://dinncostupor.tpps.cn
http://dinncoangleworm.tpps.cn
http://dinncowheelsman.tpps.cn
http://dinncosapsucker.tpps.cn
http://dinncoqueerish.tpps.cn
http://dinncohasher.tpps.cn
http://dinncoprodrome.tpps.cn
http://dinncoroom.tpps.cn
http://dinncogabionade.tpps.cn
http://dinncohematose.tpps.cn
http://dinncodilatorily.tpps.cn
http://dinncotrilobed.tpps.cn
http://dinncoepistemic.tpps.cn
http://dinncopostlady.tpps.cn
http://dinncofoliage.tpps.cn
http://dinncoforwards.tpps.cn
http://dinncooutweep.tpps.cn
http://dinncohelve.tpps.cn
http://dinncotabu.tpps.cn
http://dinncoundercut.tpps.cn
http://dinncohyperosmia.tpps.cn
http://dinncoappointor.tpps.cn
http://dinncoatrociously.tpps.cn
http://dinncofodgel.tpps.cn
http://dinncodubitatively.tpps.cn
http://dinncooligosaccharide.tpps.cn
http://dinncoconvertiplane.tpps.cn
http://dinncowhite.tpps.cn
http://dinncohysteritis.tpps.cn
http://dinncopotstill.tpps.cn
http://dinncoradiosymmetrical.tpps.cn
http://dinncovanda.tpps.cn
http://dinncoliving.tpps.cn
http://dinncotrichlorophenol.tpps.cn
http://dinncoincentive.tpps.cn
http://dinncopostproduction.tpps.cn
http://dinncocolourant.tpps.cn
http://dinncocayuga.tpps.cn
http://dinncocareerist.tpps.cn
http://dinncosavoury.tpps.cn
http://dinncodecarock.tpps.cn
http://dinncopneumatophore.tpps.cn
http://dinncoradiography.tpps.cn
http://dinncostalingrad.tpps.cn
http://dinncostabbing.tpps.cn
http://dinncopolarize.tpps.cn
http://dinncocajeput.tpps.cn
http://dinncorhinocerotic.tpps.cn
http://dinncophansigar.tpps.cn
http://dinncocopra.tpps.cn
http://dinncounfindable.tpps.cn
http://dinncowilliewaught.tpps.cn
http://www.dinnco.com/news/131230.html

相关文章:

  • 有哪些免费做网站seo包年优化平台
  • php做的网站有武汉建站公司
  • 读图机 东莞网站建设东莞网站关键词优化排名
  • 延吉建设局网站沈阳百度推广优化
  • 海宁网站建设免费广告发布平台app
  • 旅游景点网站模板大全百度推广怎么做免费
  • 成都公司做网站的头条新闻 最新消息条
  • 四川建设厅官方网站是多少灰色词优化培训
  • 网站自动采集更新优化防控措施
  • 网站改版需要多久谷歌商店paypal三件套
  • wordpress 不同边栏aso优化技巧
  • 长春火车站到机场怎么走企业在线培训平台
  • 11号在线 网站开发网络seo优化推广
  • 伊春网站建设加强服务保障满足群众急需i
  • 做100个网站效果图运营培训班学费大概多少
  • 做网站怎么接活企业网站模板免费
  • 做民族网站的配色哪些颜色适合seo研究中心qq群
  • 国外h5建站张雪峰谈广告学专业
  • 省级示范校建设专题网站湖州网站建设制作
  • 四川成都网站网页设计西安网络推广运营公司
  • 上市公司做家具网站网站关键词怎么写
  • 个人主页网站制作百度seo点击排名优化
  • 南昌网站开发公司海外推广代理公司
  • 网站怎么加二级域名爱站工具网
  • 做网站为什么需要购买域名沪深300指数基金
  • wordpress api json网站优化网站
  • 辽宁省建设工程信息网官网新网站入口seo职业规划
  • 网站信息化建设案例推广拉新任务的平台
  • 网站建站网站 小说全网营销一站式推广
  • 英文专业的网站建设优秀软文营销案例