Jump to content

Checking for a connection


Recommended Posts

(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 :lmao:

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

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 by greenmachine
Link to comment
Share on other sites

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 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

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 by greenmachine
Link to comment
Share on other sites

nevermind. duh. I have it TCPRecv-ing in a constant loop. i can check to see if it returns ""

i knew that[/sarcasm] :lmao:

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...