Archived
1
0
Fork 0

Make server continous

This commit is contained in:
Simon V. Lejel 2024-02-10 14:24:15 +01:00
parent 3b782e664a
commit 63bd78aeb0
Signed by: sl
GPG key ID: 6544A0430A2CFFAD

View file

@ -1,6 +1,7 @@
#include <arpa/inet.h>
#include <iostream>
#include <netinet/in.h>
#include <ostream>
#include <sys/socket.h>
#include <unistd.h>
@ -8,12 +9,7 @@ using std::cout, std::endl, std::string;
int main() {
struct Message {
string content;
string username;
};
cout << "Initializing server";
cout << "Initializing server" << endl;
int serverSocket = socket(AF_INET, SOCK_STREAM, 0);
if (serverSocket == -1) {
// TODO error
@ -40,9 +36,11 @@ int main() {
// TODO error
}
char buffer[1024] = { 0 };
recv(clientSocket, buffer, sizeof(buffer), 0);
cout << "Message from client " << buffer << endl;
while (true) {
char buffer[1024] = {0};
recv(clientSocket, buffer, sizeof(buffer), 0);
cout << buffer << endl;
}
close(serverSocket);