diff --git a/src/chat/client/main.c b/src/chat/client/main.c index 8a4186f..96f027b 100644 --- a/src/chat/client/main.c +++ b/src/chat/client/main.c @@ -1,8 +1,34 @@ #include +#include +#include +#include -int main(void) +#include + +int main() { - printf("Here will be client...\n"); + int sockD = socket(AF_INET, SOCK_STREAM, 0); + + struct sockaddr_in servAddr; + + servAddr.sin_family = AF_INET; + servAddr.sin_port = htons(9001); + servAddr.sin_addr.s_addr = INADDR_ANY; + + int connectStatus = connect(sockD, (struct sockaddr*) &servAddr, sizeof(servAddr)); + + if (connectStatus == -1) + { + printf("Error...\n"); + } else + { + char strData[255]; + + recv(sockD, strData, sizeof(strData), 0); + send(sockD, "NE", 3, 0); + + printf("Message: %s\n", strData); + } return 0; } \ No newline at end of file diff --git a/src/chat/server/main.c b/src/chat/server/main.c index 4846609..a554935 100644 --- a/src/chat/server/main.c +++ b/src/chat/server/main.c @@ -1,8 +1,41 @@ #include +#include +#include +#include + +#include int main(void) { - printf("Here will be server...\n"); + int servSockD = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET + + //TODO: REMOVE + char serMsg[255] = "Message from the server to the " + "client \'Hello Client\' "; + + //DEFINE SERVER ADDRESS + struct sockaddr_in servAddr; + + servAddr.sin_family = AF_INET; + servAddr.sin_port = htons(9001); + servAddr.sin_addr.s_addr = INADDR_ANY; + + //BIND SOCKET + bind(servSockD, (struct sockaddr*) &servAddr, sizeof(servAddr)); + + //LISTEN + listen(servSockD, 1); + + //CLIENT SOCKET + int clientSocket = accept(servSockD, NULL, NULL); + + char clientMsg[255]; + + //SEND + send(clientSocket, serMsg, sizeof(serMsg), 0); + recv(clientSocket, clientMsg, sizeof(clientMsg), 0); + + printf("%s\n", clientMsg); return 0; } \ No newline at end of file