Connects to a TCP client and exchanges the current time. Supported in windows console version 2.35 and later. Not the free DOS version.
******************************************************************* * Program: TCPServer.q * * Author : Dan Clarke * * Written: 10/31/2005 * * Purpose: This program demonstrates a simple TCP echo server. * * It was written to be used with program TCPClient.q * * It receives a message from the client and responds * * with the current time. * * 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, a good book is * * "TCP/UP Sockets in C, Practical Guide for Programmers" * * by Michael J. Donahoo and Kenneth L. Calvert. * * ISBN: 1-55860-826-5 * ******************************************************************* equate IPADDRESS '127.0.0.1' * Using Internal Loopback address equate PORT '7' set windowtitle to 'QuikCode TCP Server - Address ' "'" IPADDRESS "'" ', Port ' PORT set windowsize to 10 80 move 20 to ssa-maxclients * Maximum number of client connections move 10000 to ssa-timeout * Socket timeout milliseconds cls 010 if ssa is open display 'Quikcode TCP Server listening on address ' "'" IPADDRESS "'" ', port ' PORT '.' perform 100 else open ssa IPADDRESS ':' PORT TCPText 51 * Open Listener socket if val-error-cd = 10048 display 'Server is already running on port ' Port display system 'pause' end else if val-error-cd <> 0 display 'Socket open error - ' noskip perform 200 . go to 010 100 move 51 to ssa-recsize read ssa * Read data from client. Client sockets are opened automatically. if ssa is eof go to 100. if val-error-cd <> 0 display 'Socket write error - ' noskip perform 200 go to 100. display 'Received record from client: ' val-client-addr display 'Recv #' ssa-readcnt ' ' ssa-recsize ' bytes ->' ssa '<' move 51 to ssa-recsize move 'Current time at QuikCode TCP Server is' to ssa move time to ssa40-51 write ssa if val-error-cd <> 0 display 'Socket read error - ' noskip perform 200 go to 100. display 'Sent #' ssa-writecnt ' ' ssa-recsize ' bytes ->' ssa '<' display go to 100130 close ssa199 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