theguy0000 Posted January 21, 2006 Share Posted January 21, 2006 (lol, you'll see me posting a lot in here about TCP for the next two weeks or so) Is there any way to check wether TCP is connected, or to tell if it has been disconnected or at least what to do when it's been disconnected? Matt The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
PartyPooper Posted January 21, 2006 Share Posted January 21, 2006 Try using the ping command to do something like ping www.google.com. Link to comment Share on other sites More sharing options...
greenmachine Posted January 22, 2006 Share Posted January 22, 2006 (edited) I'm assuming you're going to have two (or more) scripts, one on each computer. They're going to be communicating back and forth. Right so far? If so, you can do this (this is how I did it): make an adlib function that connects and sends ONLINE every 30 seconds, and/or a function that sends OFFLINE when exiting. Of course, you're going to need to know the IP to connect to, so you can do that a few ways. Either hardcode it in, or make a function that you can call to change it. If you don't get a response, it's offline. If you do, it's online. @PartyPooper: Ping is good, but mostly to check if the computer's on the internet in general and able to be accessed. If he's doing a TCP program of some kind, just being able to ping the other computer won't help. Edited January 22, 2006 by greenmachine Link to comment Share on other sites More sharing options...
theguy0000 Posted January 22, 2006 Author Share Posted January 22, 2006 (edited) no, well yes you are correct, but I have a server program, and I need it to check itself to make sure it's connected. edit: what if it pinged itself? would that work even if it werent connected to the internet? edit2: ok let me clarify. I need a function that would work if it is connected to the internet, but would return a different value if not connected to the internet, basically. Edited January 22, 2006 by theguy0000 The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
greenmachine Posted January 22, 2006 Share Posted January 22, 2006 (edited) Connected to what? The internet? Or check to see if it's available for TCP? Edit - hmm. I believe when you do TCPStartup() it would return 0 if you can't start it. Also - TCPListen(@IPAddress1, $port) would return -1 if you can't listen on that port (if you have no internet, it should do that for all of them). Oh, and TCPAccept($MainSocket) - where $MainSocket is the socket returned by TCPListen (assuming it worked). That belongs in a loop, and so I'm assuming that once you lose connection it will fail (and return -1). Edited January 22, 2006 by greenmachine Link to comment Share on other sites More sharing options...
theguy0000 Posted January 22, 2006 Author Share Posted January 22, 2006 nevermind. duh. I have it TCPRecv-ing in a constant loop. i can check to see if it returns "" i knew that[/sarcasm] The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
greenmachine Posted January 22, 2006 Share Posted January 22, 2006 I don't know if that's right either.. because if you have that in a loop, it shouldn't be receiving data at all times, which means that tcprecv will return blank for the majority of the time. Link to comment Share on other sites More sharing options...
theguy0000 Posted January 22, 2006 Author Share Posted January 22, 2006 (edited) oh yeah...i guess i could check @error then.. Edited January 22, 2006 by theguy0000 The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now