-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit to docker repo for container
- Loading branch information
0 parents
commit d5849d2
Showing
25 changed files
with
1,713 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# clientServer | ||
Client Server socket for EE450 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
This code is the EE450 Project. | ||
-Gustavo Salazar | ||
|
||
This code block consists of a handful of files: | ||
-clientA.c ,clientA.h | ||
-clientB.c, clientB.h | ||
-serverM.c, serverM.h | ||
-serverA.c, serverA.h | ||
-serverB.c, serverB.c | ||
-serverC.c, serverC.c | ||
-socketHelper.c, socketHelper.h | ||
|
||
A brief discription of each: | ||
|
||
clients files consit of command feature as per the project description. | ||
There exist a way for a user within the block files to to check there current ammount (or wallet). There exist a way for generating transactions for user to user if the user exists in the block chain. Lastly, there exist a command to constuct a sorted list through the following command "./clientX TXLIST." Where X is either A or B. Constructing the exist will appear "alicoin.txt." This is true for both A and B clients. In addition, these file call some helper functions located in socketHelper that are used accross all the files. | ||
|
||
The main server connects through udp for back end servers and udp servers. The back end servers job duty is to read in the text file and send all of its conents through a udp port, after requested from the main server, where it is than parsed in the main server. In addition, the main server will take its contents and fgure out of a transaction is needed or was just checking the wallet either way main server does the heavy lifting in this program. The main server will disscussed in greater detail below. | ||
|
||
The socket Helper file is just a file that stores more helper functions to reduce copy and paste of the same code across multiple locations. The purpose is to just to have easy access to functions. | ||
|
||
|
||
Potentail Bugs: | ||
When testing the program there seemed to be no orginal problems except for waiting a slight time between shutting down and starting up servers between each excuttion this might happen while testing. I found that waiting for a couple seconds between each interval allows all sockets and process to appear. | ||
|
||
I have performed a series of text never, the less the was not perform with such a large data set. Thus I am unsure that this will work for huge text file. I tried by best to increase the data that could be sent accross but it could be more than I tested. Thus there might be a loss of data or text might be truncated. | ||
|
||
Next, to generate the textfile alicoin.txt, it was under the assumpition that nomore than 1000 lines (per piazzaa) will be contained in the blockfiles each. | ||
|
||
lastly, the client names will not appear. currently there was a bug when trying to find the client name | ||
|
||
|
||
Detail description of ServerM: | ||
|
||
Server M does most of the work and thus requires greater detail to describe its work. I will break down each case serverM handles in the clock. | ||
|
||
-Wallet Transaction: | ||
The wallet starts from the client. the client will appened the phrase " WALLET" to message. This will allow the main server to use the function "containsWallet" to see what task to perform. In this case when the key word wallet is in the phrase serverM knows this will be a Wallet task. The server M has been implemented with a Poll and is constant listening to either client A or client B for information. Once the message is recived from the client serverM will than send it to its "perform wallet task" where its is asking all backend servers to send over its information (i.e. the text files content). The main server will parse all these files and see if the user name exist in any one of these files. If it does not exist than it will send a tcp message to the client saying the approaite message on clients window. If the username does exist it will add or subtract up all transactions with that name and call and send the correct information to the client. | ||
|
||
- Transaction: | ||
The transaction portion of this code does simialr steps done in wallet in that it asks the back end servers to send its information over. Once its sent over the code will than add if possible to reciving user and create the transaction statement. Once this statement exist it will send this statement to a random server where the statement will be uploaded to that server's text file. Next, the appropriate information was sent out to its client | ||
- Sorted List: | ||
Firstly, serverM will confirm that the message from client contained "TXLIST." Once confirmed the server will grab all the information from from the following files and sort them based on serial id to write to the "alicoin.txt" It is important to note that this might not work for case larger than size of the array. | ||
|
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
int init_socket(char * port_number); | ||
int send_msg(int my_socket_disc,char * msg, int message_size); | ||
int transaction(int my_socket_disc,char * msg); | ||
void recv_msg_clients(int my_socket_disc); | ||
int containsKill(char *msg); | ||
int msgIsEmpty(char * msg); | ||
|
||
#include "clientA.h" | ||
#include "socketHelper.h" | ||
|
||
int main(int argc, char * argv[]){ | ||
//USCID:9281603623 | ||
//udp port: 21623 | ||
//TCP client A 25623 | ||
//TCP client B 26623 | ||
int input_argument=0; | ||
char port_number[]= "25623"; | ||
printf("The client A us up and running.\n"); | ||
int my_socket_disc=init_socket(port_number); | ||
char msg[200]; | ||
//printig public message | ||
|
||
input_argument = argc-1; | ||
switch ( input_argument ){ | ||
case 1: ; | ||
if(containsTXLIST(argv[1])){ | ||
//perform txList task | ||
printf("Sent a sorted list request to the main server.\n"); | ||
memset(msg,'\0',sizeof(msg)); | ||
strncat(msg,argv[1],strlen(argv[1])); | ||
send_msg(my_socket_disc,msg,strlen(msg)); | ||
} | ||
else{ | ||
//checkwallet | ||
printf("%s sent a blance enquiry request to the main server.\n",argv[1]); | ||
memset(msg,'\0',sizeof(msg)); | ||
strncat(msg,argv[1],strlen(argv[1])); | ||
char check_wallet_str[]=" WALLET";//space needed for dlimeter parsing | ||
strncat(msg,check_wallet_str,strlen(check_wallet_str)+1); | ||
send_msg(my_socket_disc,msg,strlen(msg)); | ||
} | ||
break; | ||
case 3: //transaction | ||
printf("%s has requested to transfer %s coins to %s.\n",argv[1],argv[2],argv[3]); | ||
memset(msg,'\0',sizeof(msg)); | ||
for(int ii=1;ii<=input_argument; ii++){ | ||
if(ii !=1){ | ||
strncat(msg," ",1); //create spaces for each except for the first time | ||
} | ||
strncat(msg,argv[ii],strlen(argv[ii])); | ||
} | ||
send_msg(my_socket_disc,msg,strlen(msg)); | ||
break; | ||
default: | ||
{ | ||
printf("There was either too many or too little input arguemnts\n"); | ||
break; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
int init_socket(char *port_num){ | ||
struct addrinfo hints, *res; | ||
memset(&hints,0,sizeof(hints)); | ||
hints.ai_family = PF_INET; | ||
hints.ai_socktype = SOCK_STREAM; | ||
getaddrinfo("localhost",port_num,&hints,&res); | ||
|
||
int mySockDesc = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | ||
if(mySockDesc <0){ | ||
printf("could not create socket\n"); | ||
return -1; | ||
} | ||
//int connect(int sockfd, struct sockaddr *serv_addr, int addrlen); | ||
int myConnection = connect(mySockDesc,res->ai_addr,res->ai_addrlen); | ||
if (myConnection <0){ | ||
printf("could not establish a connection\n"); | ||
return -1; | ||
} | ||
|
||
return mySockDesc; | ||
} | ||
|
||
|
||
|
||
int send_msg(int my_socket_disc,char * msg,int message_size){ | ||
int mySend= send(my_socket_disc, msg,message_size,0); | ||
if( mySend <0){ | ||
printf("could not send data.\n"); | ||
}else{ | ||
recv_msg_clients(my_socket_disc); | ||
} | ||
close(my_socket_disc); | ||
return 0; | ||
} | ||
|
||
void recv_msg_clients(int my_socket_disc){ | ||
int kill_command=0; | ||
char msg_from_server[500]; | ||
while(!kill_command){ | ||
memset(msg_from_server,'\0',sizeof(msg_from_server)); | ||
recv(my_socket_disc, msg_from_server,sizeof(msg_from_server),0); | ||
|
||
if(!containsKill(msg_from_server) || msgIsEmpty(msg_from_server)){ | ||
if(!msgIsEmpty(msg_from_server)){ | ||
printf("%s\n",msg_from_server); | ||
} | ||
}else{ | ||
kill_command=1; | ||
} | ||
} | ||
} | ||
|
||
int msgIsEmpty(char * msg){ | ||
if(strlen(msg) ==0){ | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
int containsKill(char *msg){ | ||
char killMsg[]="KILL"; | ||
if (strstr(killMsg,msg)){ | ||
return 1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef CLIENT_A_H | ||
#define CLIENT_A_H | ||
#pragma once | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
#include <netdb.h> | ||
#include <sys/types.h> | ||
#include <netinet/in.h> | ||
#include <sys/socket.h> | ||
#include <arpa/inet.h> | ||
#include <sys/wait.h> | ||
|
||
|
||
|
||
#endif |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
int init_socket(char * port_number); | ||
int send_msg(int my_socket_disc,char * msg, int message_size); | ||
int transaction(int my_socket_disc,char * msg); | ||
void recv_msg_clients(int my_socket_disc); | ||
int containsKill(char *msg); | ||
int msgIsEmpty(char * msg); | ||
|
||
#include "clientB.h" | ||
#include "socketHelper.h" | ||
|
||
int main(int argc, char * argv[]){ | ||
//USCID:9281603623 | ||
//udp port: 21623 | ||
//TCP client A 25623 | ||
//TCP client B 26623 | ||
int input_argument=0; | ||
char port_number[]= "26623"; | ||
printf("The client B us up and running.\n"); | ||
int my_socket_disc=init_socket(port_number); | ||
char msg[200]; | ||
//printig public message | ||
|
||
input_argument = argc-1; | ||
switch ( input_argument ){ | ||
case 1: ; | ||
if(containsTXLIST(argv[1])){ | ||
//perform txList task | ||
printf("Sent a sorted list request to the main server.\n"); | ||
memset(msg,'\0',sizeof(msg)); | ||
strncat(msg,argv[1],strlen(argv[1])); | ||
send_msg(my_socket_disc,msg,strlen(msg)); | ||
} | ||
else{ | ||
//checkwallet | ||
printf("%s sent a balance enquiry request to the main server.\n",argv[1]); | ||
memset(msg,'\0',sizeof(msg)); | ||
strncat(msg,argv[1],strlen(argv[1])); | ||
char check_wallet_str[]=" WALLET";//space needed for dlimeter parsing | ||
strncat(msg,check_wallet_str,strlen(check_wallet_str)+1); | ||
send_msg(my_socket_disc,msg,strlen(msg)); | ||
} | ||
break; | ||
case 3: //transaction | ||
printf("%s has requested to transfer %s coins to %s.\n",argv[1],argv[2],argv[3]); | ||
memset(msg,'\0',sizeof(msg)); | ||
for(int ii=1;ii<=input_argument; ii++){ | ||
if(ii !=1){ | ||
strncat(msg," ",1); //create spaces for each except for the first time | ||
} | ||
strncat(msg,argv[ii],strlen(argv[ii])); | ||
} | ||
send_msg(my_socket_disc,msg,strlen(msg)); | ||
break; | ||
default: | ||
{ | ||
printf("There was either too many or too little input arguemnts\n"); | ||
break; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
int init_socket(char *port_num){ | ||
struct addrinfo hints, *res; | ||
memset(&hints,0,sizeof(hints)); | ||
hints.ai_family = PF_INET; | ||
hints.ai_socktype = SOCK_STREAM; | ||
getaddrinfo("localhost",port_num,&hints,&res); | ||
|
||
int mySockDesc = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | ||
if(mySockDesc <0){ | ||
printf("could not create socket\n"); | ||
return -1; | ||
} | ||
//int connect(int sockfd, struct sockaddr *serv_addr, int addrlen); | ||
int myConnection = connect(mySockDesc,res->ai_addr,res->ai_addrlen); | ||
if (myConnection <0){ | ||
printf("could not establish a connection\n"); | ||
return -1; | ||
} | ||
|
||
return mySockDesc; | ||
} | ||
|
||
|
||
|
||
int send_msg(int my_socket_disc,char * msg,int message_size){ | ||
int mySend= send(my_socket_disc, msg,message_size,0); | ||
if( mySend <0){ | ||
printf("could not send data.\n"); | ||
}else{ | ||
recv_msg_clients(my_socket_disc); | ||
} | ||
close(my_socket_disc); | ||
return 0; | ||
} | ||
|
||
void recv_msg_clients(int my_socket_disc){ | ||
int kill_command=0; | ||
char msg_from_server[500]; | ||
while(!kill_command){ | ||
memset(msg_from_server,'\0',sizeof(msg_from_server)); | ||
recv(my_socket_disc, msg_from_server,sizeof(msg_from_server),0); | ||
|
||
if(!containsKill(msg_from_server) || msgIsEmpty(msg_from_server)){ | ||
if(!msgIsEmpty(msg_from_server)){ | ||
printf("%s\n",msg_from_server); | ||
} | ||
}else{ | ||
kill_command=1; | ||
} | ||
} | ||
} | ||
|
||
int msgIsEmpty(char * msg){ | ||
if(strlen(msg) ==0){ | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
int containsKill(char *msg){ | ||
char killMsg[]="KILL"; | ||
if (strstr(killMsg,msg)){ | ||
return 1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef CLIENT_B_H | ||
#define CLIENT_B_H | ||
#pragma once | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
#include <netdb.h> | ||
#include <sys/types.h> | ||
#include <netinet/in.h> | ||
#include <sys/socket.h> | ||
#include <arpa/inet.h> | ||
#include <sys/wait.h> | ||
|
||
|
||
|
||
#endif |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
CC = gcc | ||
RM = rm | ||
CFLAGS = -g -Wall | ||
|
||
all: serverM serverA serverB serverC clientA clientB | ||
|
||
clientA: clientA.c socketHelper.h | ||
$(CC) $(CFLAGS) socketHelper.c clientA.c -o clientA | ||
|
||
clientB: clientB.c socketHelper.h | ||
$(CC) $(CFLAGS) socketHelper.c clientB.c -o clientB | ||
|
||
serverM: serverM.c socketHelper.h | ||
$(CC) $(CFLAGS) socketHelper.c serverM.c -o serverM | ||
|
||
serverA: serverA.c socketHelper.h | ||
$(CC) $(CFLAGS) socketHelper.c serverA.c -o serverA | ||
|
||
serverB: serverB.c socketHelper.h | ||
$(CC) $(CFLAGS) socketHelper.c serverB.c -o serverB | ||
|
||
serverC: serverC.c socketHelper.h | ||
$(CC) $(CFLAGS) socketHelper.c serverC.c -o serverC | ||
|
||
|
||
clean: | ||
$(RM) serverM | ||
$(RM) serverA | ||
$(RM) serverB | ||
$(RM) serverC | ||
|
||
$(RM) clientA | ||
$(RM) clientB |
Binary file not shown.
Oops, something went wrong.