/* This is the client program for the switch. It sends a message to a server with the command "ON" or "OFF". The client program isn't very special. It is simply designed in this case to be run as a cgi script from a webpage, although it can be activated from a command line as well. As with my doorbell program, I have designed the client and server separately and allow them to work over a TCP/IP network. This provides the greatest amount of flexibility, as it is generally unwise to hook up experimental devices to production machines. I use a $30 486/66 to operate the switch, and that is the total risk of this project as a result. This program takes as arguments, the IP address of the switch server, the port number to use, and the command. If you have questions about this, or any of my other programs, feel free to contact me at: restil@alignment.net */ #include #include #include #include #include #include #include #include #include main(argc, argv) int argc; char *argv[]; { int sock; int rval; struct sockaddr_in server; struct hostent *hp, *gethostbyname(); char buf[1024]; char s[1024]; int x,y,z; char c; char host[20]; char *fname; int fd, status; int temp; int timeleft; int numinqueue; gets(host); temp = 0; /* 0 if currently NOT pressed, 1 is currently pressed */ sock = socket(AF_INET, SOCK_STREAM, 0); if(sock < 0) { perror("opening stream socket"); exit(1); } server.sin_family = AF_INET; hp = gethostbyname("doorbell"); if(hp == (struct hostent *)0) { fprintf(stderr,"%s: unknown host", "doorbell"); exit(2); } bcopy(hp->h_addr, &server.sin_addr, hp->h_length); server.sin_port = htons(5201); if((connect(sock, &server, sizeof(server)), 0) < 0) { perror("connecting stream socket"); exit(1); } strcpy(s,""); sprintf(s,"RCCAR WAITQUEUE 0 %s",host); if((write(sock, s, strlen(s)), 0) < 0) perror("writing on stream socket"); if(( rval = read(sock, buf, 1024)) < 0) perror("Reading from stream socket"); close(sock); printf("Buffer: %s\n",buf); for(x=0;xRC Car Wait Queue Monitor\n"); if(numinqueue >= 0) { printf("You are currently in the wait queue. You have approximately %d seconds to wait. There are %d people ahead of you in the queue.\n",timeleft,numinqueue); } else if(timeleft >= 0) { printf("You currently have control of the car. You have %d seconds left.\n",timeleft); } else printf("There is no lock.\n"); printf("\n"); }