forked from mirrors/qotd
Vendored
+7
@@ -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": []
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
#include "client.h"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../server/config.h
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user