diff options
Diffstat (limited to 'shared/hook.c')
-rw-r--r-- | shared/hook.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/shared/hook.c b/shared/hook.c index fd6ce2b..eda76db 100644 --- a/shared/hook.c +++ b/shared/hook.c @@ -11,11 +11,13 @@ #include "hook.h" -void chat(int is_client, int sockfd) +static bool client; + +void chat(int sockfd) { char buff[MAX_BUFFER_SIZE]; int n; - if (is_client){ + if (client){ for (;;) { bzero(buff, sizeof(buff)); printf("Enter the string : "); @@ -51,13 +53,13 @@ void chat(int is_client, int sockfd) } } -int start_chat( int is_client ) +int start_chat() { int sockfd, connfd; socklen_t len; struct sockaddr_in servaddr, cli; sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (is_client) + if (client) { if (sockfd == -1) { printf("socket creation failed...\n"); @@ -79,7 +81,7 @@ int start_chat( int is_client ) else printf("connected to the server..\n"); - chat(is_client, sockfd); + chat(sockfd); close(sockfd); } @@ -120,9 +122,29 @@ int start_chat( int is_client ) else printf("server accept the client...\n"); - chat(is_client, connfd); + chat(connfd); close(sockfd); } return 0; } + +void set_client() +{ + client = true; +} + +bool is_client() +{ + return client; +} + +void set_server() +{ + client = false; +} + +bool is_server() +{ + return !client; +}
\ No newline at end of file |