{\scriptsize \begin{lstlisting}
     1	/**
     2	   @file Server- and Client-Testprogram for the linemonitor functions.
     3	
     4	   @param server server to be connected (clientprogram only)
     5	
     6	   @param port to be connected (client) or port to be listened (server)
     7	
     8	   @param soft_msec (int) timeout in milliseconds which causes
     9	   soft-real-time exception.
    10	
    11	   @param hard_msec (int) timeout in milliseconds which causes
    12	   hard-real-time exception.
    13	
    14	   @param wait_msec (int) timeout for resent -- sending of the next
    15	   ping.
    16	*/
    17	
    18	/*
    19	  Copyright (c) Andreas Hofmeier
    20	  (www.an-h.de, www.an-h.de.vu, www.lgut.uni-bremen.de/an-h/)
    21	  
    22	  This program is free software; you can redistribute it and/or modify
    23	  it under the terms of the GNU General Public License as published by
    24	  the Free Software Foundation; either version 2 of the License, or
    25	  (at your option) any later version.
    26	
    27	  This program is distributed in the hope that it will be useful, but
    28	  WITHOUT ANY WARRANTY; without even the implied warranty of
    29	  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    30	  General Public License for more details.
    31	
    32	  You should have received a copy of the GNU General Public License
    33	  along with this program; if not, write to the Free Software
    34	  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    35	*/
    36	
    37	#include <stdio.h>
    38	#include "libcomm.h"
    39	
    40	
    41	/** Exception Function, print exception code and meaning on the
    42	    screen
    43	*/
    44	linemonitor_exception(char *server, int port, int type) {
    45	  printf("linemonitor_exception(%s, %d, %d): ",
    46		  server, port, type);
    47	  switch (type) {
    48	  case 0:
    49	    printf("Connecion Fault\n");
    50	    break;
    51	  case 1:
    52	    printf("Soft Real Time Exception\n");
    53	    break;
    54	  case 2:
    55	    printf("HARD Real Time Exception\n");
    56	    break;
    57	  case 3:
    58	    printf("Transmission Fault\n");
    59	    break;
    60	  case 4:
    61	    printf("Emergency Stop\n");
    62	    break;
    63	  } /* switch() */
    64	}
    65	
    66	
    67	main(int argc, char *argv[]) {
    68	  char buf[255];
    69	  int fd = 0;
    70	
    71	  // Client Mode: Server Port soft_msec hard_msec wait_msec
    72	  if (argc == 6) {
    73	    printf("Client Mode\n");
    74	    linemonitor(argv[1], atoi(argv[2]),
    75			atoi(argv[3]), atoi(argv[4]), atoi(argv[5]),
    76			linemonitor_exception);
    77	  }
    78	
    79	
    80	  // Server Mode: Port soft_msec hard_msec wait_msec
    81	  if (argc == 5) {
    82	    printf("Server Mode\n");
    83	    fd = linemonitor_server(atoi(argv[1]),
    84			       atoi(argv[2]), atoi(argv[3]), atoi(argv[3]),
    85			       linemonitor_exception);
    86	  }
    87	
    88	  if ((argc != 5) && (argc != 6)) {
    89	    printf("Client Mode: %s server port soft_msec hard_msec wait_msec\n" \
    90		   "Server Mode: %s port soft_msec hard_msec wait_msec\n\n", argv[0], argv[0]);
    91	    exit(0);
    92	  }
    93	
    94	  while (1) {
    95	    gets(buf);
    96	    linemonitor_emergencystop(fd);
    97	  }
    98	}
\end{lstlisting}}
