日期:2014-05-17 浏览次数:21012 次
WSADATA wsaData; SOCKET ServerSocket; SOCKET NewSocket; SOCKADDR_IN ServerAddr; SOCKADDR_IN ClientAddr; int ClientAddrLen; int ServerPort = 4000; char ReceiveBuffer[1024]; int Result; int ReceiveLen; if ((Result = WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0) { printf("WSAStartup failed with error %d\n", Result); return ; } ServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ServerSocket < 0) { printf("socket failed with error %d\n", WSAGetLastError()); return ; } //memset(&ServerAddr, 0, sizeof(ServerAddr)); ServerAddr.sin_family = AF_INET; ServerAddr.sin_port = htons(ServerPort); ServerAddr.sin_addr.s_addr = htonl(INADDR_ANY); //ServerAddr.sin_addr.s_addr = inet_addr("202.11.11.1" ); Result = bind(ServerSocket, (SOCKADDR*) &ServerAddr, sizeof(ServerAddr)); if (Result < 0) { printf("bind failed with error %d\n", WSAGetLastError()); return ; }