Hi. I just finished writing a simple HTTP server for a class assignment (finished in the sense that I could turn the code in and get an A for it). But there's a problem with it: so far, the only way to exit the server is to hit Control-C (fyi, I'm programming on a remote Sun unixbox). I'm fine with this, so long as I can find a way to run some closing lines of code when Control-C is entered, so the socket that the server is using is freed up when the program is exited.
Another option I've looked into is listening for a specific keypress. I've done something similar with microprocessor coding using interrupts. I tried to implement this approach, but it didn't work; maybe I'm missing something. Once the key (eg. 'q') is pressed, the program would need to run the socket closing function, then return 0, regardless of what the server is doing.
Any ideas in either direction would help a lot. Thanks!