× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Jerry,

I have a socket server program supporting multiple connections. I
want to be able to gracefully shut down the server program. So I
thought I'd use a socket client to connect to the server program and
through a socket connection tell the server program to end.

Be careful of this! Make sure that the application is only available inside a trusted network, or that the server only accepts "shutdown" requests after verifying that the command came from within the same system.

Otherwise you run the risk of a hacker (or disgruntled employee) writing a program to continually send the "Shut down" message to prevent your application from working.


In my client program, when I perform the gethostbyname function, it returns a null. So I deduced that it can't resolve since the
communication is 'redunant' (for lack of a better term), since the
client and server are already 'connnected' by virtue of their
existence on the same system.

Nope, I don't agree with your conclusion. My programs are able to look up the local computer's domain name without error. You can also look up the name 'localhost' which is the conventional name for IP address 127.0.0.1, connecting to that IP address should always connect to a program on the same host. (That IP address is a special value just for that purpose.)

If your client program has no need to ever connect to a different computer, you can also use the special value INADDR_LOOPBACK when you build your sockaddr data structure for the connect API. For example:

D connto ds likeds(sockaddr_in)

connto = *allx'00';
connto.sin_family = AF_INET;
connto.sin_port = <whatever the port number is>
connto.sin_addr = INADDR_LOOPBACK;

rc = connect(mySock: %addr(connto): %size(connto));

The idea is that INADDR_LOOPBACK will always connect to the same computer. But, gethostbyname() should work... either by using a name that can be found in DNS (or the host table) that matches your current computer, or by using the special value 'localhost' (which is in the host table by default)

So the question is can I use a socket client connection to tell my
server program to shutdown when both programs are on the same system?

Yeah, that should be no problem at all.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.