资源简介
WIN32平台下 select 模型客户端的简单聊天对话代码,vs2008可以打开
代码片段和文件信息
///客户端
#include
#include
#include
using namespace std;
#pragma comment(lib“ws2_32.lib“)
DWORD WINAPI Recv( LPVOID lpParameter);
bool socketSelect(SOCKET socketint Timeoutbool Read);
char recvBuf[100]=“0“;//accept the information
char getInput[100]=“0“;//store the input
SOCKET soc=NULL;
SOCKADDR_IN sockSrv;
int main()
{
HANDLE hThread;
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested=MAKEWORD(11);
err=WSAStartup(wVersionRequested&wsaData);
if(err!=0)
{
return 0;
}
if(LOBYTE(wsaData.wVersion)!=1 || HIBYTE(wsaData.wVersion)!=1 )
{
WSACleanup();
return 0;
}
soc=socket(AF_INETSOCK_STREAMIPPROTO_TCP);
sockSrv.sin_addr.S_un.S_addr=inet_addr(“211.80.203.73“);
sockSrv.sin_family=AF_INET;
sockSrv.sin_port=htons(6000);
int con=connect(soc(sockaddr*)&sockSrvsizeof(SOCKADDR));//connect to the server avaliable
if(con==SOCKET_ERROR)
{
cout<<“connect error!“< return 0;
}
//the second stage
hThread=CreateThread(NULL0RecvNULL0NULL);
while(getInput!=“q“)
{
cout<<“please input your words:“< cin>>getInput;
if(socketSele
- 上一篇:c++builder做图像处理项目的核心代码
- 下一篇:FIR算法Fir.c
评论
共有 条评论