Advertisement
Guest User

msgSender.c

a guest
Feb 25th, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include "msg.h"
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <sys/neutrino.h>
  6. #include <time.h>
  7.  
  8. //struct msg {
  9.   //int length;
  10.   //char data[200];
  11. //} amsg;
  12.  
  13. int main (int ac, char **argv) {
  14.   int nd, pid, chid, coid;
  15.   FILE *pidFile;
  16.   char buff[200];
  17.   char *pidFileName;
  18.  
  19.   MESSAGE amsg;
  20.  
  21.   pidFileName = malloc(strlen(argv[1]) + 5);
  22.  
  23.   strcpy(pidFileName, argv[1]);
  24.   strcat(pidFileName, ".pid");
  25.  
  26.   if (ac < 2 || (pidFile = fopen(pidFileName, "r")) == NULL) {
  27.     fprintf(stderr, "Usage: %s serverName\n", argv[0]);
  28.     exit (EXIT_FAILURE);
  29.   }
  30.  
  31.   if (fscanf(pidFile, "%d%d%d", &nd, &pid, &chid) != 3) {
  32.     fprintf(stderr, "%s: Unable to read pid from %s \n", argv[0], argv[1]);
  33.     exit (EXIT_FAILURE);
  34.   }
  35.  
  36.   fclose(pidFile);
  37.  
  38.   coid = ConnectAttach(nd, pid, chid, 0, 0);
  39.  
  40.   int c;
  41.  
  42.   printf("Enter the type of message (max 3 digits): ");
  43.   fflush(stdout);
  44.  
  45.    scanf("%d", stdin, &c);
  46.    
  47.    printf("Enter the  message: \n ");
  48.    fflush(stdout);
  49.    
  50.   while(getchar() != '\n') {
  51.  
  52.          fgets(buff, sizeof(buff), stdin);
  53.  
  54.    }
  55.  
  56.   amsg.m_hdr = c;
  57.   strcpy(amsg.m_data, buff);
  58.   MsgSend (coid, &amsg, sizeof(amsg.m_data)+strlen(amsg.m_data), NULL, 0);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement