7 static char *rcsid_tcl_c = "$Header$";
10 /************************************************************************/
15 /* Author: Noah Mendelsohn (IBM T.J. Watson Research and MIT Project
18 /* Copyright: 1986 MIT Project Athena
20 /************************************************************************/
25 /* A simple GDB client program. This program is the client in a
26 /* server/client pair. It does a start server connection and then
27 /* sends characters to the server for echoing.
32 /* 1) For simplicity, and do demonstrate the interactive response
33 /* of GDB connections, this program echoes single characters,
34 /* represented as ASCII coded integers. Because of the polymorphism
35 /* inherent in the send_object and receive_object functions,
36 /* similar one line calls are used to transmit entire tuples
37 /* (aggregates of typed fields), relations (aggregates of tuples,
38 /* which are customarily represented by linked lists), etc.
40 /* 2) All communication done by this program and any other
41 /* GDB based program is supported across incompatible
42 /* machine types. For example, this program may run on an
43 /* RT/PC while the server may be running on a Vax. Since
44 /* these machines use differing representations for integers,
45 /* GDB must do the necessary byte order conversions.
47 /* 4) Though this program is straightforward, it includes all
48 /* necessary error checking of the communication
49 /* path to the server. For example, this program will
50 /* terminate gracefully if the server crashes or is terminated
51 /* while this client is running.
54 /************************************************************************/
69 /*----------------------------------------------------------*/
73 /*----------------------------------------------------------*/
75 CONNECTION server; /* this represents the */
78 int data; /* the input as typed */
79 char c; /* same input as a char */
80 /* instead of an int */
82 /*----------------------------------------------------------*/
84 /* EXECUTION BEGINS HERE
86 /* Make sure the command line specifies the name
87 /* of the host on which the server program is running.
89 /*----------------------------------------------------------*/
95 fprintf(stderr, "tcl <server-host-name:service-i.d.>\n");
96 fprintf(stderr, "\tservice-i.d. is from #port number or name from /etc/services.\n");
97 fprintf(stderr, "\tShould match name service i.d. given to tsr.\n");
101 /*----------------------------------------------------------*/
103 /* Initialize the GDB library.
105 /*----------------------------------------------------------*/
109 /*----------------------------------------------------------*/
111 /* Try for a connection to the server on the
114 /*----------------------------------------------------------*/
116 printf("Attempting connection to server: %s\n", argv[1]);
118 server = start_server_connection(argv[1], "Dummy parms");
120 if (server == NULL) {
121 fprintf(stderr,"Could not start connection to server\n");
125 printf("Server connection started successfully.\n");
127 /*----------------------------------------------------------*/
129 /* Put the terminal into CBREAK mode, so that we'll
130 /* see each character as it's typed. Also, turn off
131 /* local character echoing, since the whole point of
132 /* this program is to echo through the network.
134 /*----------------------------------------------------------*/
136 ioctl(0, TIOCGETP, &sgtty); /* go into cbreak */
137 sgtty.sg_flags |= CBREAK;
138 sgtty.sg_flags &= ~ECHO;
139 ioctl(0, TIOCSETP, &sgtty); /* go into cbreak */
141 /*----------------------------------------------------------*/
143 /* Start reading from keyboard and writing to server.
144 /* Send each character to the server separately, and
145 /* when it is echoed, present it on the screen. <CRLF>
146 /* processing is done locally. Loop until CTRL_D (EOT)
149 /*----------------------------------------------------------*/
151 printf("Start typing data to be uppercased and echoed. ^D Exits.\n\n\n");
156 while (data != EOT) {
157 if (send_object(server, (char *)&data, INTEGER_T) ==
159 fprintf(stderr,"\n\nSend error.\n");
162 if (receive_object(server, (char *)&data, INTEGER_T) ==
164 fprintf(stderr,"\n\nSend error.\n");
174 /*----------------------------------------------------------*/
176 /* Put terminal back into normal line-at-a-time with
179 /*----------------------------------------------------------*/
181 sgtty.sg_flags |= ECHO;
182 sgtty.sg_flags &= ~CBREAK;
183 ioctl(0, TIOCSETP, &sgtty); /* go into cbreak */
185 /*----------------------------------------------------------*/
187 /* Terminate the connection to the server.
189 /*----------------------------------------------------------*/
191 printf("\n\nClosing connection\n\n");
192 sever_connection(server);