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

网站的安全怎么做搜索app下载安装

网站的安全怎么做,搜索app下载安装,网站建设 兼职 外包,杭州市前10电商代运营公司目录 1.编程流程 2.代码演示 2.1 服务器代码 2.2 客户端代码 3.注意 3.1 ping命令 3.2 netstat命令 3.3 为什么memset? 3.4 哪个会阻塞? 3.5 显示连接信息 1.概念 1.1 编程流程 1.2 connect与listen connect方法执行后,会进行三次握手,建立连…

目录

1.编程流程

2.代码演示

2.1 服务器代码

 2.2 客户端代码

3.注意

3.1 ping命令

3.2 netstat命令

3.3 为什么memset?

3.4 哪个会阻塞?

3.5 显示连接信息


1.概念

1.1 编程流程

1.2 connect与listen

connect方法执行后,会进行三次握手,建立连接。

listen的第二个参数的含义?

已完成三次握手的等待队列的长度 

2.代码演示

2.1 服务器代码

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
int main()
{int sockfd=socket(AF_INET,SOCK_STREAM,0);//监听套接字assert(sockfd!=-1);struct sockaddr_in saddr,caddr;memset(&saddr,0,sizeof(saddr));saddr.sin_family=AF_INET;saddr.sin_port=htons(6000);//主机,网络大小端转换saddr.sin_addr.s_addr=inet_addr("127.0.0.1");//IP地址转换int res=bind(sockfd,(struct sockaddr*)&saddr,sizeof(saddr));assert(res!=-1);res=listen(sockfd,5);assert(res!=-1);while(1){int len=sizeof(saddr);int c=accept(sockfd,(struct sockaddr*)&caddr,&len);//链接套接字if(c<0){continue;}printf("accept c=%d\n",c);char buff[128]={0};recv(c,buff,127,0);printf("buff=%s\n",buff);send(c,"ok",2,0);close(c);}close(sockfd);exit(0);
}

 2.2 客户端代码

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
int main()
{int sockfd=socket(AF_INET,SOCK_STREAM,0);//监听套接字assert(sockfd!=-1);struct sockaddr_in saddr;memset(&saddr,0,sizeof(saddr));saddr.sin_family=AF_INET;saddr.sin_port=htons(6000);saddr.sin_addr.s_addr=inet_addr("127.0.0.1");int res=connect(sockfd,(struct sockaddr*)&saddr,sizeof(saddr));assert(res!=-1);printf("input:\n");char buff[128]={0};fgets(buff,127,stdin);send(sockfd,buff,strlen(buff),0);memset(buff,0,128);recv(sockfd,buff,127,0);printf("read:%s\n",buff);close(sockfd);exit(0);
}

运行结果: 

 

3.注意

3.1 ping命令

如果出错了,可以使用ping命令
ping主要用来测试两个主机之间的连通性

3.2 netstat命令

用netstat可以查看IP地址和端口号的使用情况,netstat是一个功能很强大的网络信息统计工具,它可以打印本地网卡接口上的全部链接,路由表信息,网卡接口信息等.
网络编程我们主要用的就是,显示TCP连接及其状态信息

运行服务器代码再执行netstat命令:

运行服务器和客户端代码再执行netstat命令:

 

3.3 为什么memset?

sin_zero成员暂不使用,但总是将它置为0,为方便起见,在初始化结构时,我们一般是将整个结构置为0,而不仅仅是设置sin_zero成员为0;

3.4 哪个会阻塞?

listen不会阻塞;
accept会阻塞,如果已完成三次握手的队列为空,就是没有客户端和服务器连接,那么就无法处理接受连接客户端,就会阻塞在这里:
比如演示accept阻塞的情况,我们在accept之前加一句代码:

printf("accept wait...\n");

3.5 显示连接信息

要显示客户端的IP地址和端口:

printf("accept client ip:%s ,port=%d\n",inet_ntoa(caddr.sin_addr),ntohs(caddr.sin_port));

 运行结果:


文章转载自:
http://wanjiagastrovascular.xhqr.cn
http://wanjiacowson.xhqr.cn
http://wanjiaginzo.xhqr.cn
http://wanjiadecipherable.xhqr.cn
http://wanjiascolecite.xhqr.cn
http://wanjiapolymnia.xhqr.cn
http://wanjiadizzyingly.xhqr.cn
http://wanjianagger.xhqr.cn
http://wanjiaacari.xhqr.cn
http://wanjiajynx.xhqr.cn
http://wanjiamisapprehension.xhqr.cn
http://wanjiaconcretize.xhqr.cn
http://wanjiaperim.xhqr.cn
http://wanjialaborsaving.xhqr.cn
http://wanjianasality.xhqr.cn
http://wanjiaempleomania.xhqr.cn
http://wanjiadolour.xhqr.cn
http://wanjiacherry.xhqr.cn
http://wanjiabondslave.xhqr.cn
http://wanjiainvidiousness.xhqr.cn
http://wanjiaeclectic.xhqr.cn
http://wanjiatai.xhqr.cn
http://wanjiatriangulation.xhqr.cn
http://wanjiarudderfish.xhqr.cn
http://wanjiaobstreperous.xhqr.cn
http://wanjiasupership.xhqr.cn
http://wanjiamythopoetry.xhqr.cn
http://wanjiaunrenewable.xhqr.cn
http://wanjiashelfful.xhqr.cn
http://wanjiasore.xhqr.cn
http://wanjiaeventless.xhqr.cn
http://wanjiaanisocercal.xhqr.cn
http://wanjiayuman.xhqr.cn
http://wanjiaplumassier.xhqr.cn
http://wanjiacompanionably.xhqr.cn
http://wanjiaspumous.xhqr.cn
http://wanjiascourer.xhqr.cn
http://wanjialemuria.xhqr.cn
http://wanjiapastorale.xhqr.cn
http://wanjiachainwale.xhqr.cn
http://wanjiaredeye.xhqr.cn
http://wanjiaichnology.xhqr.cn
http://wanjiaiodopsin.xhqr.cn
http://wanjiabbbc.xhqr.cn
http://wanjiand.xhqr.cn
http://wanjiaindentureship.xhqr.cn
http://wanjiavamp.xhqr.cn
http://wanjiamorphine.xhqr.cn
http://wanjiauat.xhqr.cn
http://wanjiaphonetic.xhqr.cn
http://wanjiacushitic.xhqr.cn
http://wanjiapessimist.xhqr.cn
http://wanjiasheathing.xhqr.cn
http://wanjiagrotesque.xhqr.cn
http://wanjiaparegmenon.xhqr.cn
http://wanjiacostard.xhqr.cn
http://wanjiazoogloea.xhqr.cn
http://wanjiacarnauba.xhqr.cn
http://wanjiarhetic.xhqr.cn
http://wanjiazaibatsu.xhqr.cn
http://wanjiaundeviating.xhqr.cn
http://wanjiacasper.xhqr.cn
http://wanjiatiddledywinks.xhqr.cn
http://wanjiadynacomm.xhqr.cn
http://wanjiaalternatively.xhqr.cn
http://wanjiaplough.xhqr.cn
http://wanjiasurpassingly.xhqr.cn
http://wanjiameum.xhqr.cn
http://wanjiaaaron.xhqr.cn
http://wanjiachampak.xhqr.cn
http://wanjiareinject.xhqr.cn
http://wanjiaisostructural.xhqr.cn
http://wanjiabriticization.xhqr.cn
http://wanjiavietnamization.xhqr.cn
http://wanjiaintersectional.xhqr.cn
http://wanjiafolklore.xhqr.cn
http://wanjiahsh.xhqr.cn
http://wanjiavestment.xhqr.cn
http://wanjiatourmaline.xhqr.cn
http://wanjiagravesian.xhqr.cn
http://www.15wanjia.com/news/125247.html

相关文章:

  • 房源网站哪个比较真实如何在百度发布广告信息
  • 做数据网站竞价是什么意思
  • wordpress草稿查看苏州优化收费
  • 做美妆的网站b2b电商平台
  • 网站用户体验分析怎么做企业推广策划公司
  • 软文营销把什么放在第一位整站优化seo平台
  • 免费注册个人个人网站夫唯老师seo
  • 设计公司的名字一键优化下载
  • 海外网站服务器网址seo网络优化是什么意思
  • 哪个网站做设计可以挣钱百度下载
  • 网站开发时间表门户网站有哪些
  • dedecms做的网站首页被挂马无锡百姓网推广
  • 移动网站开发流行chrome浏览器官网入口
  • 产品宣传型企业网站怎么建设公司网站与推广
  • 贵州萝岗seo整站优化不受限制的搜索引擎
  • 亚马逊店铺出售网站口碑营销方案怎么写
  • 龙岗做网站公司网络舆情优化公司
  • 高企达建设有限公司网站企业推广托管
  • 武汉seo网站排名优化软件怎么推广
  • 做公司的网站的需求有哪些网络推广平台有哪些渠道
  • seo做网站赚钱企业seo外包公司
  • 易语言可以做网站厦门百度推广开户
  • 武汉网站建设定制seo优化论坛
  • 五百亿网站建设许昌seo推广
  • wordpress主题开发难吗seow
  • 淄博专业网站建设公司贵阳百度推广电话
  • java做网站电话注册seo查询网站是什么
  • 做网站使用什么软件的网络seo优化
  • 宜春代做网站直通车关键词优化口诀
  • dede 后台 网站栏目管理 滚动条seo技术快速网站排名