/////////////////////////////
// 08.07.21 - Simple_Server
/////////////////////////////
#include<winsock2.h>
#include<stdio.h>
#pragma comment(lib, "ws2_32.lib")
int main()
{
SOCKET sd;
SOCKADDR_IN ser_addr;
char buf[1024];
WSADATA data;
WSAStartup(0x0202, &data);
sd = socket(AF_INET , SOCK_STREAM , 0);
ser_addr.sin_family = AF_INET;
ser_addr.sin_port = htons(8888);
ser_addr.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
memset(&ser_addr.sin_zero, 0 , sizeof(ser_addr.sin_zero));
bind(sd , (SOCKADDR*)&ser_addr , sizeof(ser_addr));
listen(sd , 10);
while(1)
{
SOCKET new_sd = accept(sd, 0 , 0);
int ret = recv(new_sd , buf , sizeof(buf), 0);
buf[ret] = 0;
printf("[%s]",buf);
send(new_sd , buf , strlen(buf),0);
closesocket(new_sd);
}
WSACleanup();
return 0;
}