付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验目掌握Client/Server结构的设计与开发方掌握Socket实验环编译器实验内容与结果TCP/IP网络环境下,不同主机上的两个应用程序通信Winsock的启动和终止——WSAStaruop(和WSACleanup(创建套接字——socket()绑定本地地址——bind(侦听连接——listen()建立套接字连接——accept()和connect()面向连接的数据传输——send()和recv()无连接的数据传输snedto()和recvfrom(输入输出多路复用——select())时间函数——GetLocalTime(WSAStaruop的函数如下intWSAStartup(WORDwVersionRequested,LPWSADATA的副版本,低位字节指定Winsock的主版本,然后用MAKEWORD(X,Y)宏获 //WinsockWORDwHighVersion;WinsockcharszDescription[WSADESCRIPTION_LEN+1];//套接字实现描述unsignedshortiMaxSockets;最大套接字数unsignedshortiMaxUdpDg;//最大数据报长度charFAR*IpVendorInfo;}WSADATA,FAR intSOCKETsocket(intaf,inttype,intaf:指定网络地址族,一般为AF_INET。 protocol:指定网络协议,一般为0,表示默认的TCP/IP协intbind(SOCKETs,conststructsockaddtFAR*name,int参数说 namesockaddrnamelensockaddrsockddrTCP/IPstruct sin_family;//指定地址族,一般为AF_INET structin_addrsin_addr;//IP sin_zero[8IPin_addrin_addr{{struct{u_shorts_w1,s_w2;}S_un_w;u_longintlisten(SOCKETs,int 指定正在等待连接的队列的最大长度,可取1~5。SOCKETaccept(SOCKETs,structsockaddrFAR*addr,intFAR*s:指定处于状态的套接字句柄。 指定一个有效的SOCKADDR_IN结构地址。addrlen:指定SOCKADDR_IN结构的长度。accept函数返回后,addr变量中会包含请求连接的客户IP地址,并返回 d(SOCKETs,constcharFAR*buf,intlen,intflagss:指定发送端套接字描 一般置0。intrecv(SOCKETs,charFAR*buf,intlen,intflagss:指定接收端套接字描*bufrecvlenbufflags:一般置0 dto(SOCKETs,constcharFAR*buf,intlen,intflags,conststructsockaddrFAR*to,inttolen;intrecvfrom(SOCKETs,charFAR*buf,intlen,intflags,structsockaddrFAR**from,intFAR*fromlen;intselect(intnfds,fd_setFAR*readfds,fd_setFAR*writefds,fd_setFAR*exceptfds,conststructtimevalFAR*timeout);nfds:本参数忽略,仅起到兼容作用 readfds:writefds(exceptfds(timeout:select()最多等待时间,对阻塞操作则为NULL。intclosesocket(socket程序(手写或者打印后作为附件程序的运行和(提供截图Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311313:51:09.4452013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311313:51:09.4452013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311313:51:09.4452013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311313:51:09.4452013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311314:03:56.148No2013113[simplex-talkclient]send6charstoserver20131132013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311314:03:56.148No2013113[simplex-talkclient]send6charstoserver20131132013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311314:03:56.148No2013113[simplex-talkclient]send6charstoserver20131132013113Windows6.1.7600](c)2009Corporation。保留所利。 [simplex-talkclient]connectiontolocalhostis[simplex-talkclient]pleaseinputyourmessage(emptyinputtohalt):[simplex-talkclient]send6charstoserver201311314:03:56.148No2013113[simplex-talkclient]send6charstoserver20131132013113实验中的问题如遇到无法编译的问题,经过改正,发现codeblocks只有在主函数默认为main.c情况下才会编译成功,然后是sleep函数,第一个S大写才能通过。最后是附程序源代码(只附主要部分代码while len=recv(new_s,buf,sizeof(buf),/*wliucomments:modifiedtostopsending*/if(strlen(buf)==0) /*wliucomments:receivedemptymessage*/printf("[simplex-talkserver]emptymessageis}
elseprintf("[simplex-talkserver]received%d\n",fputs(buf,stdout); ACKto
}}if(strlen(buf)==1 /*wliucomments:userinputemptymessagewith
buf[0]=send(s,buf,1,printf("[simplex-talkclient]emptymessageissend}elsebuf[MAX_BUFSIZE-1]=len=strlen(buf)+1;send(s,buf,len,0); server\n",strlen(buf)); printf("NoAck\n"); server\n",strlen(buf)); }}while len=recv(new_s,buf,sizeof(buf),/*wliucomments:modifiedtostopsending*/if(strlen(buf)==0) /*wliucomments:receivedemptymessage*/printf("[simplex-talkserver]emptymessageis}elseprintf("[simplex-talkserver]received%d\n",fputs(buf,stdout); printf("sendACKto server]received%dchars\n",fputs(buf,stdout); }}if(strlen(buf)==1 /*wliucomments:userinputemptymessagewith
buf[0]=send(s,buf,1,printf("[simplex-talkclient]emptymessageissend}elsebuf[MAX_BUFSIZE-1]=len=strlen(buf)+1;send(s,buf,len,0);printf("[simplex- printf("NoAck\n"); server\n",strlen(buf)); }}while len=recv(new_s,buf,sizeof(buf),/*wliucomments:modifiedtostopsending*/if(strlen(buf)==0) /*wliucomments:receivedemptymessage}
printf("[simplex-talkserver]emptymessageiselseprintf("[simplex-talkserver]received%d\n",fputs(buf,stdout); ACKto
printf("[simplex-talkserver]received%dchars\n",fputs(buf,stdout); ACKto
}}if(strlen(buf)==1 /*wliucomments:use
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年AI驱动的临床诊断创新政策环境研究
- 2025年终身学习理念下课程顾问服务生态构建
- (正式版)DB41∕T 1249-2023 《地理标志产品 永城面粉》
- 护理人员的信息技术应用
- 2025年秋新人教版数学3年级上册全册同步教案
- 2026医疗器械趋势报告撰写指南试行
- 护理基础知识讲解
- 能化集团招聘实施工程师考题
- 母婴护理技术培训课件:宝宝语言与沟通能力培养
- 烟台业达笔试历年考题及答案
- 2026湖南长沙开福区数铸科技有限责任公司招聘1人考试备考试题及答案解析
- 2026年安全生产月主题宣贯课件
- Q-SY 13034-2024 物料主数据数字化描述规范
- 移动通信课后习题答案(第六版 章坚武著)
- 烟草公司运用PDCA循环便携式安全检查工具集合装置的研制QC成果汇报
- 培智3年级《认识人民币》
- 青春期男女如何正确两性交往
- 高警示药物处方审核要点
- SB/T 10347-2017糖果压片糖果
- 能源塔热泵系统介绍课件
- GB/T 16508.4-2013锅壳锅炉第4部分:制造、检验与验收
评论
0/150
提交评论