mirror of
https://github.com/Hizenberg469/My-Own-Redis.git
synced 2026-04-20 02:52:22 +03:00
Simple Hello Server/Client program
This commit is contained in:
38
Server-Client Program/Client/Client.cbp
Normal file
38
Server-Client Program/Client/Client.cbp
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="Client" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/Client" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/Client" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="main.cpp" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
52
Server-Client Program/Client/Client.cpp
Normal file
52
Server-Client Program/Client/Client.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
//Client side program in C/C++
|
||||
|
||||
#include <stdint.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
static void msg( const char* msg){
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
}
|
||||
|
||||
static void die(const char* msg){
|
||||
int err = errno;
|
||||
fprintf(stderr, "[%d] %s\n", err,msg);
|
||||
abort();
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if( fd < 0 ){
|
||||
die("socket()");
|
||||
}
|
||||
|
||||
struct sockaddr_in addr = {};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = ntohs(1234);
|
||||
addr.sin_addr.s_addr = ntohl(INADDR_LOOPBACK);// 127.0.0.1
|
||||
int rv = connect(fd, (const struct sockaddr*)&addr, sizeof(addr));
|
||||
if( rv ){
|
||||
die("connect");
|
||||
}
|
||||
|
||||
char msg[] = "hello";
|
||||
write(fd, msg, strlen(msg));
|
||||
|
||||
char rbuf[64] = {};
|
||||
ssize_t n = read(fd, rbuf , sizeof(rbuf) - 1);
|
||||
if( n < 0 ){
|
||||
die("read");
|
||||
}
|
||||
printf("server says: %s\n", rbuf);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
12
Server-Client Program/Client/Client.depend
Normal file
12
Server-Client Program/Client/Client.depend
Normal file
@@ -0,0 +1,12 @@
|
||||
# depslib dependency file v1.0
|
||||
1699986008 source:/home/hizenberg/Desktop/My Own Redis/Server-Client Program/Client/Client.cpp
|
||||
<stdint.h>
|
||||
<netinet/ip.h>
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
<string.h>
|
||||
<sys/socket.h>
|
||||
<unistd.h>
|
||||
<errno.h>
|
||||
<arpa/inet.h>
|
||||
|
||||
BIN
Server-Client Program/Client/bin/Debug/Client
Executable file
BIN
Server-Client Program/Client/bin/Debug/Client
Executable file
Binary file not shown.
BIN
Server-Client Program/Client/client
Executable file
BIN
Server-Client Program/Client/client
Executable file
Binary file not shown.
BIN
Server-Client Program/Client/obj/Debug/Client.o
Normal file
BIN
Server-Client Program/Client/obj/Debug/Client.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user