Page 1 of 1

Sockets... checking if client is still online

Posted: Sat Feb 12, 2005 5:40 pm
by Chris Corbyn
Hi,

Put simply I want to provide a link to ftp running on my pc but only if my pc is connected to the internet at the time, otherwise just display a short message saying "Offline".

I'll keep a script running on my pc when it's on to acheive this if need be but I basically need some way of only displaying the link to my ftp if it's actually going to open otherwise visitors will just get a not found error.

I believe this can be done with sockets? Is this gonna be easy to do?

I should point out that I know nothing about sockets....

Thanks

Posted: Sat Feb 12, 2005 7:45 pm
by Kieren
What you want to do is try to open the socket but if it wont then produce your message.

However the message will appear for any reason the socket isn't open though, not just because your computer isn't connected to the internet.

You also don't need to use sockets. You could use PHP's FTP functions. Below is an example of what you are tring to do:

ftp_connect("ftp.yourserver.com") or die("Couldn't connect to server");

Posted: Sun Feb 13, 2005 6:23 am
by Chris Corbyn
Your ftp_connect() idea is much better thanks... How that didn't spring to mind I don't know. , since I'm currently writing an ftp client in PHP :lol:

My pc has a dynamic IP, so the way it was gonna work was that some script regularly updates the current IP (stored in db or text file) of my pc on the domain my site is hosted from. Then if ftp_connect() returns true for the presence of a ftp connection on the current IP, the link to it is displayed. I'll have to come up with a decent way of keeping an up to date IP stored though (although to be honest I'm on broadband so it doesn't change often cos I'd rarely disconnect/reconnect - I should just run a quick script once a day and every time I reconnect - not have one running every 5 mins or so)...

Thanks very much for your better idea :-)

Posted: Sun Feb 13, 2005 9:03 am
by feyd
why not use a dynamic ip DNS service? no-ip or dyndns or someone..