- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
tcp、ip通信(TCP and IP communications)
tcp、ip通信(TCP and IP communications)
Sockets (2012-09-08 22:02:57) TCP sockets programming gradually we label Reprint: sockets programming
In Windows Sockets, specify the IP address and port number using the SOCKET_IN structure.
Struct socket_in{
Short sin_family;
U_short sin_port;
Struct in_addr sin_addr;
Char sin_zero[8];
}
Where sin_family must be AF_INET;
The sin_port range is 1024~49151;
Sin_addr saves the IP address to a value of 4 bytes.
[than basic TCP programming function than]
You need to include the header file #include winsock.h
1.WSAStartup () function
Is the first Windows Sockets function that the socket application must call.
The following code shows how the application that supports only Windows Sockets 1.1 is called WSAStartup ():
WORD wVersionRequested; / / DLL version
WSADATA wsaData; / / dynamic library information
Int err;
WVersionRequested = MAKEWORD (1, 1); the //MAKEWORD () function specifies the version number
Err = WSAStartup (wVersionRequested, wsaData);
If (ERR = = 0) {
The available DLL / / not found
Return;
}
If (LOBYTE (wsaData.wVersion) = 1! || HIBYTE (wsaData.wVersion) = {1!)
Return / / 2.2 version of the DLL is not
WSACleanup ();
Return;
}
2.socket () function
Create socket.
SOCKET s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); / / create a UDP, the two parameter is SOCK_DGRAM, IPPROTO_UDP
If (INVALID_SOCKET = s)
{
/ / socket creation failed
}
3.bind () function
Bind a socket to a known address.
SOCKET s; / / socket
Struct sockaddr_in servAddr; / / server socket address
Int nServPort = 5500; / / server port
Int nErrCode; / / error code
/ / define server address
ServAddr.sin_famliy = AF_INET;
ServAddr.sin_addr.S_addr = htonl (INADDR_ANY);
ServAddr.sin_port = htons (nServPort);
Bind / socket
NErrCode = bind (s, (SOCKADDR*) servAddr, sizeof (servAddr));
If (SOCKET_ERROR = nErrCode)
{
Bind the socket / failure
}
4.listen () function
Set socket to monitor mode.
SOCKET s; / / socket
Int nErrCode; / / error code
/ / monitor
NErrCode = list
您可能关注的文档
- 03.3.牛顿第二定律(03.3. Newton's second law).doc
- ++兰州大学风雨百年发展历程_卫视_凤凰网2().doc
- 007_黄仁宇现象(007_ Huang Renyu phenomenon).doc
- 002机械挖土施工工艺(002 mechanical excavation construction technology).doc
- 007如何创建html表格(007 how to create a HTML table).doc
- 008_盼(008_ look forward to).doc
- 0.5元(0.5 yuan).doc
- 033牛顿第二定律(033 Newton's second law).doc
- 002汽车美容店投资创业方案(002 auto beauty shop investment venture program).doc
- 04 配套cad笔记(04 matching CAD notes).doc
- touzilunwen(touzilunwen).doc
- the giver(给予者).doc
- tracert(跟踪路由)(Tracert (trace routing)).doc
- ts16949 考试试题及答案(TS16949 examination questions and answers).doc
- twi主从机通讯的程序(atmega16)(Twi master slave communication program (ATmega16)).doc
- ubuntu下svn服务器安装配置(Svn server installation configuration under Ubuntu).doc
- ups监控软件应用和发展(Application and development of UPS monitoring software).doc
- u盘常见故障及检修(Common faults and repair disk).doc
- ubuntu下编译c程序(Ubuntu下编译C程序).doc
- u盘进修(U study).doc
最近下载
- DBJT 08-120-2015雨水口标准图2015沪S203.docx VIP
- 神经介入产品培训.ppt VIP
- 重庆市綦江区郭扶镇社区工作者招聘考试试题汇总2024.docx VIP
- ECharts数据可视化课件 第1章 初识ECharts.pptx VIP
- 重庆市綦江区安稳镇社区工作者招聘考试试题汇总2024.docx VIP
- 突发事故处理流程.pdf VIP
- 电工安全生产协议书(完整版).docx VIP
- 固定翼无人机技术完整全套教学课件.pdf
- 1.35KV预制舱变电站项目(整套35KV预制舱,变压器,开关柜,火灾报警)技术规范书.doc VIP
- DB36_T 811-2020 井冈蜜柚 生产技术规程.pdf VIP
文档评论(0)