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

大连seo网站推广网站如何做快捷支付接口

大连seo网站推广,网站如何做快捷支付接口,管理咨询公司业务类型,wordpress 非80端口127.0.0.1本地回环ip#xff0c;用于本地测试#xff0c;不会进行网络通信 TCP是面向连接的#xff0c;服务器比较被动 需要服套接字监听 listen状态 正常通信默认会进行主机序列和网络序列的转换 TcpServer.cc #pragma once#includeiostream #includestring…127.0.0.1本地回环ip用于本地测试不会进行网络通信 TCP是面向连接的服务器比较被动 需要服套接字监听 listen状态 正常通信默认会进行主机序列和网络序列的转换 TcpServer.cc #pragma once#includeiostream #includestring #includecstring #includesys/types.h #includesys/socket.h #includecstdlib #includewait.h #includearpa/inet.h #includenetinet/in.h #includeunistd.h #includesignal.hconst int defaultfd-1; const std::string defaultip0.0.0.0; const int backlog5; class TcpServer; class ThreadData { public:ThreadData(int fd,const std::string ip,const uint16_t p,TcpServer* tsvr):sockfd(fd),clientip(ip),clientport(p),tsvr_(tsvr){} public:int sockfd;std::string clientip;uint16_t clientport;TcpServer* tsvr_; }; class TcpServer { public:TcpServer(const uint16_t port,const std::string ipdefaultip):listensockfd_(defaultfd),port_(port),ip_(ip){}void InitServer(){listensockfd_socket(AF_INET,SOCK_STREAM,0);if(listensockfd_0){std::coutcreate socket errorstd::endl;}std::coutcreate socket successstd::endl;struct sockaddr_in local;memset(local,0,sizeof(local));local.sin_familyAF_INET;local.sin_porthtons(port_);inet_aton(ip_.c_str(),(local.sin_addr));if(bind(listensockfd_,(struct sockaddr*)local,sizeof(local))0){std::coutbind errorstd::endl;}// TCP是面向连接的服务器比较被动if(listen(listensockfd_,backlog)0){std::coutlisten errorstd::endl;}std::coutlisten successstd::endl;}static void* Routine(void* args){pthread_detach(pthread_self());ThreadData* tdstatic_castThreadData*(args);td-tsvr_-Service(td-sockfd,td-clientip,td-clientport);delete td;return nullptr;}void Start(){for(;;){//1.获取连接struct sockaddr_in client;socklen_t lensizeof(client);// sock返的fd负责listen状态//accept返回的sockfd负责通信int sockfdaccept(listensockfd_,(struct sockaddr* )client,len);if(sockfd0){std::coutaccept errorstd::endl;}uint16_t clientportntohs(client.sin_port);char clientip[32];inet_ntop(AF_INET,(client.sin_addr),clientip,sizeof(clientip));std::coutget a net link... sockfd : sockfdstd::endl;sleep(1);// 根据新连接来通信// Service(sockfd, clientip,clientport);// close(sockfd);// 多进程版// pid_t idfork();// if(id0)// {// close(listensockfd_);// if(fork()0) exit(0);// Service(sockfd, clientip,clientport); //孙子进程system 领养// close(sockfd);// exit(0);// }// //father// close(sockfd);// // 关掉子进程 // pid_t ridwaitpid(id,nullptr,0);// (void)rid;// 多线程版本ThreadData*tdnew ThreadData(sockfd,clientip,clientport,this);pthread_t tid;pthread_create(tid,nullptr,Routine,nullptr);}}void Service(int sockfd,const std::string clientip,const uint16_t clientport){char buffer[4096];while(true){ssize_t n read(sockfd,buffer,sizeof(buffer));if(n0){buffer[n]0;std::coutclient say# bufferstd::endl;std::string echo_stringtcpserver echo#;echo_stringbuffer;write(sockfd,echo_string.c_str(),echo_string.size());}else if(n0){break;}else{std::cout read errorstd::endl;}}}~TcpServer(){} private:int listensockfd_;uint16_t port_;std::string ip_; }; TcpClient #includeiostream #includecstring #includesys/types.h #includesys/socket.h #includecstdlib #includearpa/inet.h #includenetinet/in.h #include unistd.h void Usage(const std::string proc) {std::cout\n\rUsage proc serveip serverport\nstd::endl; } int main(int argc,char*argv[]) {if(argc!3){Usage(argv[0]);exit(1);}int sockfdsocket(AF_INET,SOCK_STREAM,0);std::string serveripargv[1];uint16_t serverportstd::stoi(argv[2]);if(sockfd0){std::cerrsock errorstd::endl;}struct sockaddr_in server;memset(server,0,sizeof(server));server.sin_familyAF_INET;server.sin_porthtons(serverport);// tcp客户端要bind// 客户端发起connect的时候进行随机bindinet_pton(AF_INET,serverip.c_str(),(server.sin_addr));int nconnect(sockfd,(struct sockaddr*)server,sizeof(server));if(n0){std::cerrconnect error...std::endl;}std::string message;while(true){std::coutPlease Enter# ;std::getline(std::cin,message);write(sockfd,message.c_str(),message.size());char inbuffer[4096];int nread(sockfd,inbuffer,sizeof(inbuffer));if(n0){inbuffer[n]0;std::coutinbufferstd::endl;}}close(sockfd);return 0; }
http://www.pierceye.com/news/962134/

相关文章:

  • 怎么在vk网站上做推广网站建设柚子网络科技官网
  • 威海网站优化公司wordpress post title
  • 网站建设验收期安阳后营吧
  • 询盘网站培训机构前端开发
  • 企业如何做网站建站小程序定制开发深圳
  • 创建网站怎么赚钱的视频博客主题wordpress
  • 北京大兴区网站建设如何打造平台
  • 建设公司网站需要多少天棋盘游戏类网站开发
  • 织梦网站logo修改探测器 东莞网站建设
  • 图片网站收录淮北网站建设求职简历
  • 北京建设局投诉网站首页晋江外贸网站建设
  • 如何更改网站模板网站建设这一行业怎样
  • 海口网站排名东网站建设
  • 李连杰做的功夫网站泉州四方网站开发
  • 台州专业网站设计系统简单的购物网站制作
  • 中国建筑信息资讯网网站的优化用什么软件
  • wordpress本地网站打开慢电商网课
  • 仿照别人的网站做违法吗江苏集团网站建设
  • 一家专门做建材的网站找人做个网站大概多少钱
  • 信息展示网站系统网站策划书怎么写
  • 吉木萨尔县建设局网站岳阳网站推广
  • 九宫格网站模板本机网站环境搭建
  • 自学网站建设 难吗企业网站制作公司合肥
  • 网站建设的网页怎么做餐饮装修公司推荐
  • 网站页面是自己做还是使用模板惠州seo外包费用
  • 深圳专业网站建设技术郑州网络推广平台有哪些
  • 网站建设的费用预算怎么查自己名下有没有注册公司
  • 深圳医院网站建设网站产品页模板
  • 文化馆网站建设做直播的网站有哪些
  • 网站首页怎样排版如何把网站放在根目录