Connects to a TCP server and exchanges the current time. Supported in windows console version 2.35 and later. Not the free DOS version.
******************************************************************* * Program: TCPClient.q * * Author : Dan Clarke * * Written: 10/31/2005 * * Purpose: This program demonstrates a simple TCP echo client. * * It was written for use with program TCPServer.q. * * It sends a time message to the server and waits for a * * response. * * Notes..: This program uses internal loopback address 127.0.0.1. * * No information is sent out to the internet. * * Info...: For more information on sockets, read the book * * "TCP/UP Sockets in C, Practical Guide for Programmers" * * by Michael Donahoo and Kenneth Calvert. * * ISBN: 1-55860-826-5 * ******************************************************************* equate IPADDRESS '127.0.0.1' * Using Internal Loopback address equate PORT '7' set windowtitle to 'QuikCode TCP Client - Address ' "'" IPADDRESS "'" ', Port ' PORT set windowsize to 10 80 move 10000 to csa-timeout * Socket timeout milliseconds cls display 'Connecting to TCP Server on address ' "'" IPADDRESS "'" ', port ' PORT '...' 010 if csa is open perform 100 else open csa IPADDRESS ':' PORT TCPText 51 if val-error-cd <> 0 display 'Socket open error - ' noskip perform 200 . go to 010 100 move 'Current time at QuikCode TCP Client is' to csa move time to csa40-51 write csa if val-error-cd <> 0 display 'Socket write error - ' noskip perform 200 go to 110. display 'Sent ' csa-recsize ' bytes ->' csa '<' sleep 500 * Sleep for 1/2 second read csa at eof 110 if val-error-cd <> 0 display 'Socket read error - ' noskip perform 200 go to 110. display 'Recv ' csa-recsize ' bytes ->' csa '<' display go to 100110 close csa sleep 500 * Sleep for 1/2 second199 exit * Display Socket Error Description 200 if val-error-cd = 10004 display 'Interrupted function call' else if val-error-cd = 10013 display 'Permission denied' else if val-error-cd = 10014 display 'Bad address' else if val-error-cd = 10022 display 'Invalid argument' else if val-error-cd = 10024 display 'Too many open files' else if val-error-cd = 10035 display 'Resource temporarily unavailable' else if val-error-cd = 10036 display 'Operation now in progress' else if val-error-cd = 10037 display 'Operation already in progress' else if val-error-cd = 10038 display 'Socket operation on nonsocket' else if val-error-cd = 10039 display 'Destination address required' else if val-error-cd = 10040 display 'Message too long' else if val-error-cd = 10041 display 'Protocol wrong type for socket' else if val-error-cd = 10042 display 'Bad protocol option' else if val-error-cd = 10043 display 'Protocol not supported' else if val-error-cd = 10044 display 'Socket type not supported' else if val-error-cd = 10045 display 'Operation not supported' else if val-error-cd = 10046 display 'Protocol family not supported' else if val-error-cd = 10047 display 'Address family not supported by protocol family' else if val-error-cd = 10048 display 'Address already in use' else if val-error-cd = 10049 display 'Cannot assign requested address' else if val-error-cd = 10050 display 'Network is down' else if val-error-cd = 10051 display 'Network is unreachable' else if val-error-cd = 10052 display 'Network dropped connection on reset' else if val-error-cd = 10053 display 'Software caused connection abort' else if val-error-cd = 10054 display 'Connection reset by peer' else if val-error-cd = 10055 display 'No buffer space available' else if val-error-cd = 10056 display 'Socket is already connected' else if val-error-cd = 10057 display 'Socket is not connected' else if val-error-cd = 10058 display 'Cannot send after socket shutdown' else if val-error-cd = 10060 display 'Connection timed out' else if val-error-cd = 10061 display 'Connection refused' else if val-error-cd = 10064 display 'Host is down' else if val-error-cd = 10065 display 'No route to host' else if val-error-cd = 10067 display 'Too many processes' else if val-error-cd = 10091 display 'Network subsystem is unavailable' else if val-error-cd = 10092 display 'Winsock dll version out of range' else if val-error-cd = 10093 display 'Successful WSAStartup not yet performed' else if val-error-cd = 10101 display 'Graceful shutdown in progress' else if val-error-cd = 10109 display 'Class type not found' else if val-error-cd = 11001 display 'Host not found' else if val-error-cd = 11002 display 'Nonauthoritative host not found' else if val-error-cd = 11003 display 'This is a nonrecoverable error' else if val-error-cd = 11004 display 'Valid name, no data record of requested type' else if val-error-cd = 0 display 'Successful' else display 'Unknown socket error' .299 exit