✨ Add client
This commit is contained in:
parent
810fb50ddd
commit
3b782e664a
1 changed files with 42 additions and 0 deletions
42
src/client/main.cc
Normal file
42
src/client/main.cc
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using std::cout, std::cin, std::endl, std::string;
|
||||
|
||||
int main() {
|
||||
|
||||
struct Message {
|
||||
char * content;
|
||||
string username;
|
||||
};
|
||||
|
||||
int clientSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
sockaddr_in serverAdress;
|
||||
serverAdress.sin_family = AF_INET;
|
||||
serverAdress.sin_port = htons(8080);
|
||||
serverAdress.sin_addr.s_addr = inet_addr("127.0.0.50");
|
||||
|
||||
while (true) {
|
||||
Message message;
|
||||
cout << "Type message to server: ";
|
||||
cin >> message.content;
|
||||
cout << endl;
|
||||
message.username = "Client 1";
|
||||
|
||||
if (strcmp(message.content, "exit") == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
cout << "Sending message to server as user: " << message.username << endl;
|
||||
send(clientSocket, message.content, strlen(message.content), 0);
|
||||
}
|
||||
|
||||
close(clientSocket);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in a new issue