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

厦门公司网站设计全网营销推广案例

厦门公司网站设计,全网营销推广案例,wordpress文章只显示标题,lnmp wordpress 502在linux下,存在着这样的情况,本地的进程间通信,并且其中一个是服务端,另外的都是客户端。 服务端通过绑定端口,客户端往127.0.0.1的对应端口发送,即可办到,不过这样会浪费一个端口,同…

在linux下,存在着这样的情况,本地的进程间通信,并且其中一个是服务端,另外的都是客户端。
服务端通过绑定端口,客户端往127.0.0.1的对应端口发送,即可办到,不过这样会浪费一个端口,同时也容易造成安全隐患。

今天发现linux服务端创建socket的时候,协议族用AF_UNIX即可,AF_LOCAL和AF_UNIX的值是一样的。

而AF_UNIX和127.0.0.1回环地址相比,具有哪些好处呢。本人读了下面博客:
Unix domain socket 简介

其中里面讲到UNIX domain socket 用于 IPC 更有效率:不需要经过网络协议栈,不需要打包拆包、计算校验和、维护序号和应答等。本人想当然认为AF_UNIX速度比127.0.0.1更快,为此鄙人进行了实验。

找一个比较大的文件,超过1G大小,然后
1。用AF_UNIX写客户端和服务端,由客户端读取文件,发送给AF_UNIX服务端,然后服务端写文件,看看用AF_UNIX传递一个文件需要多久。
2. 用127.0.0.1写客户端和服务端,由客户端读取文件,发送给127.0.0.1服务端,然后服务端写文件,看看用127.0.0.1传递一个文件需要多久。

废话不多说,直接上代码,先上AF_UNIX的:
AF_UNIX服务端(unixsocketserver.c):

#include <stdlib.h>  
#include <stdio.h>  
#include <stddef.h>  
#include <sys/socket.h>  
#include <sys/un.h>  
#include <errno.h>  
#include <string.h>  
#include <unistd.h>  
#include <ctype.h>   #define MAXLINE 80  char *socket_path = "/tmp/server.socket";  #define RECV_LEN 1000int main(void)  
{  fd_set readmask, exceptmask;struct timeval tv;int maxfd = FD_SETSIZE;int nready = 0;FILE *fp = fopen("/tmp/pull_desktop234_copy.flv", "w");if(fp == NULL){perror("fopen pull_desktop234_copy.flv failed");goto end;} char buf[RECV_LEN + 1];int readbyte, writebyte;struct sockaddr_un serun, cliun;  socklen_t cliun_len;  int listenfd, connfd, size;  if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {  perror("socket error");  exit(1);  }  memset(&serun, 0, sizeof(serun));  serun.sun_family = AF_UNIX;  strcpy(serun.sun_path, socket_path);  size = offsetof(struct sockaddr_un, sun_path) + strlen(serun.sun_path);  unlink(socket_path);  if (bind(listenfd, (struct sockaddr *)&serun, size) < 0) {  perror("bind error");  exit(1);  }  printf("UNIX domain socket bound\n");  if (listen(listenfd, 20) < 0) {  perror("listen error");  exit(1);          }  printf("Accepting connections ...\n");  cliun_len = sizeof(cliun);         if ((connfd = accept(listenfd, (struct sockaddr *)&cliun, &cliun_len)) < 0){  perror("accept error");  goto end;  }time_t now, endtime;now = time(NULL);while(1){FD_ZERO(&readmask);FD_ZERO(&exceptmask);FD_SET(connfd, &readmask);FD_SET(connfd, &exceptmask);tv.tv_sec = 3;tv.tv_usec = 0;nready = select(maxfd, &readmask, NULL, &exceptmask, &tv);if(nready < 0){goto end;}if(nready == 0){printf("nready == 0\n");continue;}if(FD_ISSET(connfd, &readmask)){readbyte = recv(connfd, buf, RECV_LEN, 0);if(readbyte < 0){perror("readbyte < 0");goto end;}if(readbyte == 0){perror("readbyte == 0");goto end;}if(readbyte > 0){buf[readbyte] = 0;writebyte = fwrite(buf, 1, readbyte, fp);if(writebyte != readbyte){printf("writebyte(%d) != readbyte(%d)\n", writebyte, readbyte);goto end;}}}if(FD_ISSET(connfd, &exceptmask)){printf("select, exceptmask\n");goto end;}}  
end:endtime = time(NULL);printf("costs %d seconds\n", endtime - now);if(fp != NULL){fclose(fp);fp = NULL;}	close(connfd);close(listenfd);  return 0;  
}

AF_UNIX客户端(unixsocketclient.c):

#include <stdlib.h>  
#include <stdio.h>  
#include <stddef.h>  
#include <sys/socket.h>  
#include <sys/un.h>  
#include <errno.h>  
#include <string.h>  
#include <unistd.h>  #define SEND_LEN 1000char *client_path = "/tmp/client.socket";  
char *server_path = "/tmp/server.socket";  int main() {  struct  sockaddr_un cliun, serun;  int len;   int sockfd, n;  FILE *fp = fopen("/tmp/pull_desktop234.flv", "r");if(fp == NULL){perror("fopen pull_desktop234.flv failed");goto end;}   if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){  perror("client socket error");  exit(1);  }  // 一般显式调用bind函数,以便服务器区分不同客户端  memset(&cliun, 0, sizeof(cliun));  cliun.sun_family = AF_UNIX;  strcpy(cliun.sun_path, client_path);  len = offsetof(struct sockaddr_un, sun_path) + strlen(cliun.sun_path);  unlink(cliun.sun_path);  if (bind(sockfd, (struct sockaddr *)&cliun, len) < 0) {  perror("bind error");  exit(1);  }  memset(&serun, 0, sizeof(serun));  serun.sun_family = AF_UNIX;  strcpy(serun.sun_path, server_path);  len = offsetof(struct sockaddr_un, sun_path) + strlen(serun.sun_path);  if (connect(sockfd, (struct sockaddr *)&serun, len) < 0){  perror("connect error");  exit(1);  }  int sendbyte = 0;int alreadysendbyte = 0;char buf[SEND_LEN + 1];while((n = fread(buf, 1, SEND_LEN, fp)) > 0){sendbyte = send(sockfd, buf, n, 0);if(sendbyte == -1){perror("send error");goto end;}alreadysendbyte += sendbyte;while(alreadysendbyte < n){sendbyte = send(sockfd, buf + alreadysendbyte, n - alreadysendbyte, 0);if(sendbyte == -1){perror("send error");goto end;}alreadysendbyte += sendbyte;}}
end:if(fp != NULL){fclose(fp);fp = NULL;}close(sockfd);return 0;  
}

接着上127.0.0.1的:
127.0.0.1服务端(loopsocketserver.c):

#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>#define RECV_LEN 1000int main(){fd_set readmask, exceptmask;struct timeval tv;int maxfd = FD_SETSIZE;int nready = 0;FILE *fp = fopen("/tmp/pull_desktop234_copy.flv", "w");if(fp == NULL){perror("fopen pull_desktop234_copy.flv failed");goto end;} char buf[RECV_LEN + 1];int readbyte, writebyte;int serv_sock=socket(AF_INET,SOCK_STREAM,0);struct sockaddr_in serv_addr;memset(&serv_addr,0,sizeof(serv_addr));serv_addr.sin_family=AF_INET;serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);serv_addr.sin_port=htons(9990);bind(serv_sock,(struct sockaddr*)&serv_addr,sizeof(serv_addr));listen(serv_sock,5);struct sockaddr_in clnt_addr;socklen_t clnt_addr_size=sizeof(clnt_addr);int clnt_sock=accept(serv_sock,(struct sockaddr*)&clnt_addr,&clnt_addr_size);time_t now, endtime;now = time(NULL);while(1){FD_ZERO(&readmask);FD_ZERO(&exceptmask);FD_SET(clnt_sock, &readmask);FD_SET(clnt_sock, &exceptmask);tv.tv_sec = 3;tv.tv_usec = 0;nready = select(maxfd, &readmask, NULL, &exceptmask, &tv);if(nready < 0){goto end;}if(nready == 0){printf("nready == 0\n");continue;}if(FD_ISSET(clnt_sock, &readmask)){readbyte = recv(clnt_sock, buf, RECV_LEN, 0);if(readbyte < 0){perror("readbyte < 0");goto end;}if(readbyte == 0){perror("readbyte == 0");goto end;}if(readbyte > 0){buf[readbyte] = 0;writebyte = fwrite(buf, 1, readbyte, fp);if(writebyte != readbyte){printf("writebyte(%d) != readbyte(%d)\n", writebyte, readbyte);goto end;}}}if(FD_ISSET(clnt_sock, &exceptmask)){printf("select, exceptmask\n");goto end;}}
end: endtime = time(NULL);printf("costs %d seconds\n", endtime - now);if(fp != NULL){fclose(fp);fp = NULL;}close(clnt_sock);close(serv_sock);return 0;
}

127.0.0.1客户端(loopsocketclient.c):

#include<sys/socket.h>
#include<arpa/inet.h>
#include<stdio.h>
#include<string.h>
#include <errno.h>
#include <stdlib.h>#define SEND_LEN 1000int main(){int sock=socket(AF_INET,SOCK_STREAM,0);FILE *fp = fopen("/tmp/pull_desktop234.flv", "r");if(fp == NULL){perror("fopen pull_desktop234.flv failed");goto end;}   int n = 0;struct sockaddr_in serv_addr;memset(&serv_addr,0,sizeof(serv_addr));serv_addr.sin_family=AF_INET;serv_addr.sin_addr.s_addr=inet_addr("127.0.0.1");serv_addr.sin_port=htons(9990);if(connect(sock,(struct sockaddr*)&serv_addr,sizeof(serv_addr)) < 0){perror("connect failed");goto end;}int sendbyte = 0;int alreadysendbyte = 0;char buf[SEND_LEN + 1];while((n = fread(buf, 1, SEND_LEN, fp)) > 0){sendbyte = send(sock, buf, n, 0);if(sendbyte == -1){perror("send error");goto end;}alreadysendbyte += sendbyte;while(alreadysendbyte < n){sendbyte = send(sock, buf + alreadysendbyte, n - alreadysendbyte, 0);if(sendbyte == -1){perror("send error");goto end;}alreadysendbyte += sendbyte;}}
end:if(fp != NULL){fclose(fp);fp = NULL;}close(sock);return 0;
}

本人的缓冲区大小分为3种情况(文件大小为1.15G),上图代码片段缓冲区大小为1000字节:
缓冲区大小100字节:AF_UNIX传递完文件费时25秒,127.0.0.1传递完文件费时33秒
缓冲区大小1000字节:AF_UNIX传递完文件费时8秒,127.0.0.1传递完文件费时7秒
缓冲区大小10000字节:AF_UNIX传递完文件费时5秒,127.0.0.1传递完文件费时4秒


文章转载自:
http://elfish.zLrk.cn
http://citybilly.zLrk.cn
http://infrequency.zLrk.cn
http://petrologist.zLrk.cn
http://pithily.zLrk.cn
http://algous.zLrk.cn
http://percentage.zLrk.cn
http://mcmxc.zLrk.cn
http://newy.zLrk.cn
http://marline.zLrk.cn
http://usafe.zLrk.cn
http://misinput.zLrk.cn
http://concretist.zLrk.cn
http://lipoprotein.zLrk.cn
http://transcurrence.zLrk.cn
http://parasang.zLrk.cn
http://degras.zLrk.cn
http://poove.zLrk.cn
http://adele.zLrk.cn
http://irrecusable.zLrk.cn
http://chromatin.zLrk.cn
http://retroflection.zLrk.cn
http://reassess.zLrk.cn
http://novennial.zLrk.cn
http://perchloride.zLrk.cn
http://football.zLrk.cn
http://priggery.zLrk.cn
http://unarmoured.zLrk.cn
http://pungent.zLrk.cn
http://preaseptic.zLrk.cn
http://polyhalite.zLrk.cn
http://hommock.zLrk.cn
http://mariner.zLrk.cn
http://flawless.zLrk.cn
http://philistine.zLrk.cn
http://draff.zLrk.cn
http://soliloquy.zLrk.cn
http://gnomon.zLrk.cn
http://laudableness.zLrk.cn
http://tonguefish.zLrk.cn
http://dissentient.zLrk.cn
http://looper.zLrk.cn
http://dermatoplasty.zLrk.cn
http://companionship.zLrk.cn
http://bebeeru.zLrk.cn
http://underlayer.zLrk.cn
http://civism.zLrk.cn
http://employment.zLrk.cn
http://bibliomaniacal.zLrk.cn
http://hoodman.zLrk.cn
http://belfried.zLrk.cn
http://enseal.zLrk.cn
http://toneme.zLrk.cn
http://myna.zLrk.cn
http://karikal.zLrk.cn
http://lymphogranuloma.zLrk.cn
http://packboard.zLrk.cn
http://flourish.zLrk.cn
http://vidar.zLrk.cn
http://swadeshi.zLrk.cn
http://warpwise.zLrk.cn
http://mileometer.zLrk.cn
http://wail.zLrk.cn
http://multipad.zLrk.cn
http://enravish.zLrk.cn
http://gairish.zLrk.cn
http://cosmic.zLrk.cn
http://platycephalous.zLrk.cn
http://egyptianization.zLrk.cn
http://stile.zLrk.cn
http://perceivable.zLrk.cn
http://thymy.zLrk.cn
http://candock.zLrk.cn
http://stepfather.zLrk.cn
http://masque.zLrk.cn
http://putridly.zLrk.cn
http://seaboard.zLrk.cn
http://nsm.zLrk.cn
http://hexastich.zLrk.cn
http://scholium.zLrk.cn
http://aggie.zLrk.cn
http://splenotomy.zLrk.cn
http://cameralist.zLrk.cn
http://tractate.zLrk.cn
http://dissonant.zLrk.cn
http://stand.zLrk.cn
http://soothingly.zLrk.cn
http://pediculate.zLrk.cn
http://attagal.zLrk.cn
http://tartrated.zLrk.cn
http://unrepealed.zLrk.cn
http://hipline.zLrk.cn
http://wonderworld.zLrk.cn
http://attune.zLrk.cn
http://pyrolyze.zLrk.cn
http://terminableness.zLrk.cn
http://xanthochroic.zLrk.cn
http://onthe.zLrk.cn
http://darrell.zLrk.cn
http://jubilantly.zLrk.cn
http://www.dt0577.cn/news/120589.html

相关文章:

  • 虚拟主机怎么设计网站吗百度热搜高考大数据
  • 做网站到底要不要备案合肥今天的最新消息
  • 网站做推广页需要什么软件seo门户 site
  • 杭seo网站建设排名河南郑州最新消息今天
  • 临海做网站学电商运营的培训机构
  • 178网站建设竞价托管资讯
  • php网站开发程序杭州最好的电商培训机构
  • 微信公众平台官网小程序seo引擎优化怎么做
  • 网站微信二维码侧边栏漂浮框seo积分系统
  • 怎么做最火的视频网站seo网站技术培训
  • 做网站的框架有2019年度最火关键词
  • 如何让自己做的博客网站上线运营网站是什么意思
  • 南阳网站建设百度推广助手电脑版
  • 广州seo团队seo免费优化网址软件
  • 高端网名生成器扬州网络优化推广
  • app开发流程设计工具网站首页seo关键词布局
  • 看优秀摄影做品的网站40个免费网站推广平台
  • 做淘客网站需要企业的域名网络视频营销平台
  • 流程图制作网页太原搜索引擎优化
  • 靠谱的做网站的公司做个网站
  • 苏州网站设计百度搜一下
  • 怎样在政府采购网站做备案张家界百度seo
  • 在淘宝上做网站如何付费营销网站建设哪家好
  • 东营做网站优化驻马店百度seo
  • 做私彩网站需注意什么百度seo如何优化
  • 建设小学瓯江校区网站西点培训前十名学校
  • 大学科研项目做网站线下推广宣传方式有哪些
  • 网站建设方案书备案河南智能seo快速排名软件
  • 龙岗网站建设哪家公司靠谱2345手机浏览器
  • 青岛建设银行网站历下区百度seo