Skip to content

Instantly share code, notes, and snippets.

@Cranc
Created April 6, 2019 11:50
Show Gist options
  • Save Cranc/0eee27f870ead97f5c468aac0bb9ad5d to your computer and use it in GitHub Desktop.
Save Cranc/0eee27f870ead97f5c468aac0bb9ad5d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <rpc/rpc.h>
#include "pub_sub.h"
int main()
{
CLIENT *cl;
char topic[TOPLEN];
char message[MESLEN];
short* result;
int len;
if(argc < 3){
fprintf(stderr,"Usage: math_client host topic message\n");
}
bzero(topic, TOPLEN);
bzero(message, MESLEN);
//copy topic
len = strlen(argv[2]);
if(len >= TOPLEN) {
fprintf(stderr, "topic as to many characters\n");
}
memcpy(topic, argv[2], len);
//copy message
len = strlen(argv[3]);
if(len >= MESLEN) {
fprintf(stderr, "message as to many characters\n");
}
memcpy(message, argv[3], len);
//connect
cl clnt_create(argv[1], PUBSUBPROG, PUBSUBVERS, "tcp");
if(cl == NULL) {
clnt_pcreateerror(argv[1]);
exit(1);
}
//subscribe
result = subscribe();
if(result == NULL){
clnt_perror(cl, argv[1]);
exit(1);
}
//publish
result = publish(message);
if(result == NULL){
clnt_perror(cl, argv[1]);
exit(1);
}
//unsubscribe
result = unsubscribe();
if(result == NULL){
clnt_perror(cl, argv[1]);
exit(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment