first version of client
CMake / build (push) Failing after 4s

This commit is contained in:
2025-02-28 12:34:45 +01:00
parent e078a1023a
commit bf7020f791
7 changed files with 81 additions and 0 deletions
+7
View File
@@ -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": []
}
+12
View File
@@ -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()
+1
View File
@@ -0,0 +1 @@
#include "client.h"
+3
View File
@@ -0,0 +1,3 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+1
View File
@@ -0,0 +1 @@
../server/config.h
+57
View File
@@ -0,0 +1,57 @@
#include <arpa/inet.h> // inet_addr()
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h> // bzero()
#include <sys/socket.h>
#include <unistd.h> // read(), write(), close()
#include <errno.h>
#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);
}