DIM
Distributed Information Management
System


4.4 Client examples


Examples

#1
The following example implements a C client. The client requests two services, one TIMED (every ten seconds) and one MONITORED. It also tells the server to execute a command.

#include <dic.h>

int buffer[10];
int no_link = -1;
int version;
 
buff_received(tag, bufferp, size)
long *tag;
char *bufferp;
 int *size;
{
int i;
 
   if(bufferp[0] == -1)
        printf("Service SERV_BY_BUFFER not available\n");
   else
   {
        printf("received service SERV_BY_BUFFER\n\t");
        for(i=0;i<10;i++)
             printf("%d ",bufferp[i]);
        printf("\n");
   }
   printf("\n");
}
 
serv_received(tag, address, size)
long *tag;
int *address, *size;
{
int i;
 
   if(*address == -1)
        printf("Service SERV_BY_ROUTINE not available\n");
   else
   {
        printf("received service SERV_BY_ROUTINE\n\t");
        for(i=0;i<10;i++)
             printf("%d ",buffer[i]);
        printf("\n");
   }
   printf("\n");
}
 
main()
{
 
   dic_info_service("SERV_BY_BUFFER", TIMED, 10,
        buffer, 40, buff_received, 0, &no_link,4);
   dic_info_service("SERV_BY_ROUTINE", MONITORED, 0,
        0, 0, serv_received, 0, &no_link,4);
   while(1)
   {
        dic_cmnd_service("SERV_CMND", "UPDATE", 7);
        sleep(5);
   }
}

The following example implements a FORTRAN client. This client requests a MONITORED service and tell the server to execute a command. 

      program test_client    
      implicit none  
  
      common/test_for/buff  
      character*80 buff    
      include 'delphi$online:[communications.dim]dic.inc'  
  
      integer*4 dic_cmnd_service  
      character*80 str  
      external recv_rout  
      external dic_info_service  
  
      buff = 'empty'  
      str = 'Command'  
      call dic_info_service('TEST/INFO',MONITORED,0,%ref(buff),80,recv_rout,  
     ,                          0,%val(0),0)  
      do while(.TRUE.)  
         call dic_cmnd_service('TEST/CMND',%ref(str),17)  
         call lib$wait(10.)  
      enddo  
      end  
  
      subroutine recv_rout(tag)  
      implicit none  
      integer*8 tag
      common/test_for/buff
      character*80 buff
      write(6,'(A,A)') ' Client : Received ',buff
      end