客户端通讯程序代码测试
2010-11-17 08:00
381 查看
#include <Winsock2.h>
#include <stdio.h>
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup( );
return;
}
SOCKET sockClient=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons(6000);
connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
char recvBuf[100];
recv(sockClient,recvBuf,100,0);
printf("%s/n",recvBuf);
send(sockClient,"This is zhangsan",strlen("This is zhangsan")*1,0);
closesocket(sockClient);
WSACleanup();
}
#include <stdio.h>
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup( );
return;
}
SOCKET sockClient=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons(6000);
connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
char recvBuf[100];
recv(sockClient,recvBuf,100,0);
printf("%s/n",recvBuf);
send(sockClient,"This is zhangsan",strlen("This is zhangsan")*1,0);
closesocket(sockClient);
WSACleanup();
}
相关文章推荐
- Linux下c语言实验Websocket通讯 含客户端和服务器测试代码
- Linux下c语言实验Websocket通讯 含客户端和服务器测试代码
- Linux下c语言实验Websocket通讯 含客户端和服务器测试代码
- Android客户端程序代码
- websocket html5 客户端测试代码
- 收集Android程序测试代码覆盖率
- 利用wsdl文件生成webservice接口的java客户端测试代码
- ZSChatServer线程设计模型---客户端测试程序
- Linux移植随笔:对tslib库的ts_test测试程序代码的一点分析【转】
- VB.Net程序代码:Hashtable与ListView结合使用测试例子
- .OpenWrt驱动程序Makefile的分析概述 、驱动程序代码参考、以及测试程序代码参考
- JAVA 测试程序代码运行时间
- 尺度不变特征变换(SIFT算法)Matlab程序代码测试例子的说明(Lowe的代码)
- 【C#】 Socket通讯客户端程序
- c# 计算程序执行时间,计算一段代码执行所用的时间,测试效率
- c#托盘程序测试代码
- SIFT算法:Matlab程序代码测试例子的说明(Lowe的代码)
- 【糟糕的代码】Android的第一个程序:简单的皮肤更换测试
- 测试一段程序代码执行时间的方法
- Java Socket通讯客户端代码详解