/************************************************************ (C) Copyright 1997 Heriot Watt University All rights reserved. File: client.c $Date: 99/03/05 $ $Revision: 0.0 $ ************************************************************/ #include "f_tcp.h" #define TRUE 1 #define FALSE 0 #define BUFFER_SIZE 20 #define PORT 10000 /*------------------------------------------------------------MAIN()---*/ void main (int argc, char *argv[]) { /* tcp/ip connection handling variables */ int FileDescriptor; char console_buffer[BUFFER_SIZE]; char ip_input_buffer[BUFFER_SIZE]; char ip_output_buffer[BUFFER_SIZE]; register int count; int i; struct hostent *host; printf("%s compiled in %s %s\n", __FILE__, __DATE__, __TIME__); if ( argc < 2 ) { printf( "The program expects arguments\n" ); printf( "client \n" ); exit(0); } if ((config_tcp_port_client(&FileDescriptor))==-1) { SysError("TCP port server: bad configuration\n"); } cl_to_ser_connection(argv[1],PORT,FileDescriptor); while( TRUE ) { /* Get a number from console */ printf( "> " ); scanf( "%s", console_buffer ); /* Convert it to integer (-1 to exit)*/ /* Make sure output buffer is empty */ bzero( ip_output_buffer, sizeof( ip_output_buffer )); /* Copy value to output buffer */ strcpy( ip_output_buffer, console_buffer ); /* Send value to server */ if ( send( FileDescriptor, ip_output_buffer, strlen(ip_output_buffer), 0 ) <= 0 ) SysError( "Error on send" ); /* Make sure input buffer is empty*/ bzero( ip_input_buffer, sizeof(ip_input_buffer) ); /* receive data back from server */ if ( recv( FileDescriptor, ip_input_buffer, sizeof(ip_input_buffer), 0 ) <= 0 ) SysError( "Error on recv" ); /*Print reception */ printf( "%s\n", ip_input_buffer ); } exit(0); } /*main()*/ void SysError( char *string ) { printf( "Error found: String given is --> %s\n", string ); exit(0); }