Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "msg.h"
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/neutrino.h>
- #include <time.h>
- //struct msg {
- //int length;
- //char data[200];
- //} amsg;
- int main (int ac, char **argv) {
- int nd, pid, chid, coid;
- FILE *pidFile;
- char buff[200];
- char *pidFileName;
- MESSAGE amsg;
- pidFileName = malloc(strlen(argv[1]) + 5);
- strcpy(pidFileName, argv[1]);
- strcat(pidFileName, ".pid");
- if (ac < 2 || (pidFile = fopen(pidFileName, "r")) == NULL) {
- fprintf(stderr, "Usage: %s serverName\n", argv[0]);
- exit (EXIT_FAILURE);
- }
- if (fscanf(pidFile, "%d%d%d", &nd, &pid, &chid) != 3) {
- fprintf(stderr, "%s: Unable to read pid from %s \n", argv[0], argv[1]);
- exit (EXIT_FAILURE);
- }
- fclose(pidFile);
- coid = ConnectAttach(nd, pid, chid, 0, 0);
- int c;
- printf("Enter the type of message (max 3 digits): ");
- fflush(stdout);
- scanf("%d", stdin, &c);
- printf("Enter the message: \n ");
- fflush(stdout);
- while(getchar() != '\n') {
- fgets(buff, sizeof(buff), stdin);
- }
- amsg.m_hdr = c;
- strcpy(amsg.m_data, buff);
- MsgSend (coid, &amsg, sizeof(amsg.m_data)+strlen(amsg.m_data), NULL, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement