diff --git a/src/server/main.cc b/src/server/main.cc index 3ccde6b..873c41f 100644 --- a/src/server/main.cc +++ b/src/server/main.cc @@ -1,19 +1,50 @@ +#include #include -#include +#include +#include +#include -using std::cout, std::cin, std::string; +using std::cout, std::endl, std::string; int main() { - while (true) { - string message; - cout << "Enter message: "; - cin >> message; + struct Message { + string content; + string username; + }; - if (message == "exit") { - break; - } + cout << "Initializing server"; + int serverSocket = socket(AF_INET, SOCK_STREAM, 0); + if (serverSocket == -1) { + // TODO error } + sockaddr_in serverAddress; + serverAddress.sin_family = AF_INET; + serverAddress.sin_port = htons(8080); + serverAddress.sin_addr.s_addr = inet_addr("127.0.0.50"); + + int bindStatus = bind(serverSocket, (struct sockaddr *)&serverAddress, + sizeof(serverAddress)); + if (bindStatus == -1) { + // TODO error + } + + int listenStatus = listen(serverSocket, 5); + if (listenStatus == -1) { + // TODO error + } + + int clientSocket = accept(serverSocket, nullptr, nullptr); + if (clientSocket == -1) { + // TODO error + } + + char buffer[1024] = { 0 }; + recv(clientSocket, buffer, sizeof(buffer), 0); + cout << "Message from client " << buffer << endl; + + close(serverSocket); + return 0; }