server.cpp
#include<windows.h>
#include<stdio.h>
#include<winsock.h>
#define SERVER_PORT 9999
#define SERVER_IP "127.0.0.1"
int main(int argc,char *argv[])
{
SOCKET serSocket,cliSocket;
struct sockaddr_in localAddr,clientAddr;
WSADATA Ws;
int Bit;
int Lit;
char recvBuf[1024];
int recvR,sen;
int cliLen;
fd_set rfds;//
struct timeval time;//
int maxrd=0;//
int ret;//
if(WSAStartup(MAKEWORD(2,2),&Ws)!=0)
{
printf("init windows socket failed:%d\n",GetLastError());
return -1;
}
serSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(serSocket==INVALID_SOCKET)
{
printf("create socket failed:%d\n",GetLastError());
return -1;
} <