/*****************************************************************************
* 	Project 	: Network Based Message Queue System		    **
*	Course		: CIS 650 - Software Engineering		    **
*	Location 	: /research/paraducks3/sameer/courses/cis650/proj/cl**
*	File		: c1.cc 	      	       			    **
*	Description 	: A client                      		    **
*****************************************************************************/

#include <iostream.h>
#include "uai.h"

struct nmsgbuf *ptr;

main()
{
  int msqid, n1, n2, clientID;

  msqid = nmsgget(6, 5);

  clientID = ngetownid();
  cout << "client id is " << clientID << endl;

  ptr = new nmsgbuf;


  ptr->mtype = 1;
  read_line(0,ptr->mtext,256);
  //cout << "ptr->mtype is " << ptr->mtype << endl;
  //cout << "ptr->mtext is " << ptr->mtext << endl;

  /* send the message */
  n1 = nmsgsnd(msqid, ptr, strlen(ptr->mtext), 0);
  if (n1 < 0) {
    cout << "nmsgsnd error" << endl;
    exit(1);
  }

  memset(ptr->mtext,0,256);
  /* receive the result */
  n2 = nmsgrcv(msqid, ptr, 256, clientID);
  if (n2 < 0) {
    cout << "nmsgsnd error" << endl;
    exit(1);
  }
  
  cout << "client: I just sent following" << endl;
  cout << ptr->mtext << endl;
  //cout << "Now the ptr->mtype is " << ptr->mtype << endl;

  delete ptr;
}



