Advertisement
Guest User

client.c

a guest
Dec 9th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7. #include "client.h"
  8. #include <string.h>
  9. #include <pthread.h>
  10.  
  11. int main(int argc, char** argv) {
  12.  
  13.     int fd_s, fd_c;
  14.     char * myfifo = "/tmp/myfifo";
  15.     request requ;
  16.    
  17.     char c_pid[10];
  18.     sprintf(c_pid, "%d", getpid());
  19.    
  20.     requ.client_pid = getpid();
  21.    
  22.     fd_s = open(myfifo, O_WRONLY);
  23.    
  24.    
  25.     // mkfifo(myfifo, 0666); /* create the FIFO (named pipe) */
  26.  
  27.     printf("<<<<<<<<<<<<Client>>>>>>>>>>>>\n\n\n");
  28.  
  29.     printf("> Welcome to Bomberman! Input commands as you wish!\n");
  30.  
  31.     while (1) {
  32.         printf("\n> ");
  33.         scanf(" %s", requ.command);
  34.  
  35.         if (strcmp(requ.command, "login") == 0) {
  36.             printf("\n> Username : ");
  37.             scanf(" %s", requ.user_username);
  38.             printf("\n> Password : ");
  39.             scanf(" %s", requ.user_password);
  40.  
  41.  
  42.  
  43.             write(fd_s, &requ, sizeof (request));
  44.            
  45.             read(fd_c, &requ, sizeof(request));
  46.  
  47.             printf("%s", requ.answer);
  48.            
  49.  
  50.         }
  51.  
  52.         if (strcmp(requ.command, "shutdown") == 0) {
  53.             exit(1);
  54.         }
  55.  
  56.     }
  57.  
  58.  
  59.  
  60.  
  61.    
  62.     close(fd_c);
  63.     close(fd_s);
  64.     unlink(myfifo); /* remove the FIFO */
  65.     return (EXIT_SUCCESS);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement