diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt new file mode 100644 index 0000000..690b913 --- /dev/null +++ b/client/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.19) +project(qotd C) + +message("STATIC_BUILD=${STATIC_BUILD}") + +set(CMAKE_C_STANDARD 99) + +add_executable(qotd_c main.c) + +if ( STATIC_BUILD ) + target_link_libraries(qotd -static) +endif() \ No newline at end of file diff --git a/client/client.c b/client/client.c new file mode 100644 index 0000000..a7f5447 --- /dev/null +++ b/client/client.c @@ -0,0 +1 @@ +#include "client.h" \ No newline at end of file diff --git a/client/client.h b/client/client.h new file mode 100644 index 0000000..81087a6 --- /dev/null +++ b/client/client.h @@ -0,0 +1,3 @@ +#include +#include +#include \ No newline at end of file diff --git a/client/config.h b/client/config.h new file mode 120000 index 0000000..a4a7b27 --- /dev/null +++ b/client/config.h @@ -0,0 +1 @@ +../server/config.h \ No newline at end of file diff --git a/client/main.c b/client/main.c new file mode 100644 index 0000000..d6af8b2 --- /dev/null +++ b/client/main.c @@ -0,0 +1,57 @@ +#include // inet_addr() +#include +#include +#include +#include +#include // bzero() +#include +#include // read(), write(), close() +#include +#include "config.h" +#define MAX 80 +#define PORT 17 +#define SA struct sockaddr + +int main() +{ + int sockfd, connfd; + struct sockaddr_in servaddr4, cli; + + unsigned int servaddrlength; + // socket create and verification + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd == -1) + { + printf("socket creation failed...\n"); + exit(0); + } + else + printf("Socket successfully created..\n"); + + // assign IP, PORT + servaddr4.sin_family = AF_INET; + servaddr4.sin_addr.s_addr = inet_addr("127.0.0.1"); + servaddr4.sin_port = htons(PORT); + + int status = connect(sockfd, (SA *)&servaddr4, sizeof servaddr4); + // connect the client socket to server socket + if (status != 0) + { + printf("%i\n", errno); + printf("connection with the server failed...\n"); + + exit(0); + } + else + printf("connected to the server..\n"); + + struct sockaddr *servaddr = (SA *)&servaddr4; + unsigned int ss = sizeof servaddr; + // function for chat + char clientMessage[MESSAGE_STRING_LENGTH] = {0}; + recvfrom(sockfd, clientMessage, MESSAGE_STRING_LENGTH, 0, servaddr, &ss); + printf("From Server : %s", clientMessage); + + // close the socket + close(sockfd); +} \ No newline at end of file diff --git a/CMakeLists.txt b/server/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to server/CMakeLists.txt