#include 
#include 
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(1, 1);
err = WSAStartup(wVersionRequested, &wsaData);
if(err != 0)
return;
if(LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)
{
WSACleanup();
return;
}
SOCKET sockSrv = socket(AF_INET, SOCK_DGRAM, 0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(8080);
bind(sockSrv, (sockaddr*)&addrSrv, sizeof(SOCKADDR));
SOCKADDR_IN addrClient;
char sendBuf[33];
char recvBuf[33];
int len = sizeof(sockaddr);
//  int len = 1;
while(true)
{
recvfrom(sockSrv, recvBuf, 33, 0, (SOCKADDR*)&addrClient, &len);
if('q' == recvBuf[0])
{
puts("quit");
sendto(sockSrv, "q", 2, 0, (sockaddr*)&addrClient, sizeof(sockaddr));
break;
}
else
{
printf("%s:\n", addrClient.sin_addr);
puts(recvBuf);
puts("Enter:");
gets(sendBuf);
sendto(sockSrv, sendBuf, strlen(sendBuf) + 1, 0, (sockaddr*)&addrClient, sizeof(sockaddr));
}
}
}

28第28行会导致程序意外终止