Online or Offline ?
Blitz3D Forums/Blitz3D Beginners Area/Online or Offline ?
| ||
Hi all, I'm trying to get the internet connection state, if the player's computer is online or offline. So I use the code above, but I always get the "Connected" message even if my modem is physically unplugged. ;************************************** If CallDLL("url.dll","InetIsOffline") Print "Not connected." Else Print "Connected!" EndIf WaitKey() ;************************************** Could someone tell me what's wrong with my code ? Thanks in advance, Gui. |
| ||
You could try creating a TCP connection or similar to a website address and if it succeeds it means the computer is online. Also, with that code you may need to specify a bank to retrieve data from the DLL. bnkData = CreateBank( 4 ) Result = CallDLL( "url.dll", "InetIsOffline", 0, bnkData ) ;Call to DLL succeeded If Result Connected = PeekInt( bnkData, 0 ) If Connected = True Print "Connected!" Else Print "Not Connected." EndIf Endif FreeBank bnkData bnkData = 0That code is untested though and is only to give a rough idea of what you might need to do to retrieve the data you want. You could also try using a userlib. |
| ||
Thanks a lot Chris, but it doesn't work. Apparently, the DLL call fails, I don't have any print output (added a waitkey() at the bottom of the code). Concerning a userlib, I don't know what it is, I'm a newbie ;-) |
| ||
Could it be that your call to the dll is also failing and that is why it always returns false and displays the connected message? |
| ||
Is this of any use?; test for an internet connection ; userlibs ; ********************************** ; .lib "wininet.decls" ; InternetCheckConnection%(Url$,Flags%,Reserved%):"InternetCheckConnectionA" ; ********************************** Const FORCE_CONNECTION = 1 url$="http://www.blitzbasic.com" If InternetCheckConnection(url$, FORCE_CONNECTION, 0) = 0 Notify "Connection NOT present" Else Notify "Connection present" End If End |
| ||
Yeah, it seems to work, thanks JimB ! |
| ||
Try OpenTCPStream. Check out the example in the Blitz Command Reference. It seems to work, I tested it by running the example with my cable modem on/off and got a "failed" message when it was turned off :) |
| ||
Problems with trying to open a TCP connection are: a) It's slow. If it's going to fail, it takes several long seconds to do so. b) If the user is on dial-up, it will pop up the connection dialog. |
| ||
c) If the website you try to connect to happens to be down at that moment, it'll say you aren't connected. |
| ||
Userlib.module "wininet.dll" InternetGetConnectedState%( Description%, ReservedValue% ) Blitz Function IsConnected%() Local ret% = 0 Return InternetGetConnectedState( ret, 0 ) End Function Im not 100% sure the Integer passing will work though. you might wonna change that to a type or bank. This is the official signature of the function: bool InternetGetConnectedState( out int Description, int ReservedValue ) |
| ||
Also, you might try GetSystemMetrics(SM_NETWORK) which apparently returns an odd number if the computer is online. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp |