Skip to content

Commit

Permalink
new client
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao-M-Almeida committed May 29, 2016
1 parent 6d1ee62 commit 551e24f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Projecto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CC = gcc
CFLAGS = -Wall -pedantic -ansi -std=gnu99 -g
DEPS = log.h debug.h item.h phash-lib.h inetutils.h TCPlib.h psiskv.h psiskv_server.h front-lib.h data-lib.h
CLIENT_OBJ = inetutils.o TCPlib.o psiskv_lib.o debug.o client.o
SCLIENT_OBJ = inetutils.o TCPlib.o psiskv_lib.o debug.o sync_client.o
FRONT_SERVER_OBJ = debug.o log.o phash-lib.o inetutils.o TCPlib.o psiskv_lib.o psiskv_server.o front-lib.o front-server.o
DATA_SERVER_OBJ = debug.o log.o phash-lib.o inetutils.o TCPlib.o psiskv_lib.o psiskv_server.o data-lib.o data-server.o
CLI1_OBJ = psiskv_lib.o inetutils.o TCPlib.o debug.o cli-exe-1.o
Expand Down Expand Up @@ -36,6 +37,10 @@ client.out: $(CLIENT_OBJ)
@echo Compiling $@
$(CC) $(CFLAGS) $^ -o $@ -pthread

sync_client.out: $(SCLIENT_OBJ)
@echo Compiling $@
$(CC) $(CFLAGS) $^ -o $@ -pthread

%.o: %.c $(DEPS)
@echo Compiling $<
$(CC) $(CFLAGS) -c $< -o $@ -pthread
Expand Down
58 changes: 58 additions & 0 deletions Projecto/sync_client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "TCPlib.h"
#include "inetutils.h"
#include "item.h"
#include "psiskv.h"
#include "debug.h"
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>


int main() {
char buf[25];
int id;
int i;
for (i = 0; i < 1; i++) {
id = fork();
if(id==0){
break;
}
}
printf("I'm client with PID: %d\n",id);
int kv = kv_connect( (char *) "127.0.0.1", 9999);
if(kv<=0){
exit(-1);
}
printf("PID: %d - Connected\n", id);
sprintf(buf,"%d",id);
printf("Writing:\n");
int r;
for (i = 0; i < 11; i++) {
r = kv_write(kv, i , buf , strlen(buf)+1, 0); /* will not overwrite*/
if(r<0){
printf("PID: %d Write error\n",id);
exit(-1);
}
}
kv_close(kv);

kv = kv_connect( (char *) "127.0.0.1", 9999);
if(kv<=0){
exit(-1);
}
for (i = 0; i < 11; i++) {
r = kv_read(kv, i , buf, 25);
if(r<0){
printf("PID: %d Read error\n",id);
exit(-1);
}
printf("PID: %d I=%d Read: %s\n",id, i, buf );
}
exit(0);
}

0 comments on commit 551e24f

Please sign in to comment.