Sign in to follow this  
Followers 0
Venix

Need Alternative Solution

11 posts in this topic

#1 ·  Posted (edited)

A few days ago I made a topic where I was struggling to make a program that would check if my friend’s minecraft server was online by connecting to it through the use of TCP. Thanks to the help of PhoenixXL I figured out what my code was missing and then made the changes to the code. When running the code at first it appeared to work perfectly and I requested my friend to turn his server on and off multiple times to make sure of this. The only problem occurred was when I tried to connect to the server whilst the program was running, unfortunately I was unable to connect to the server with ease and the connection would often be interrupted whilst logging in. I believe this is because of limitations with TCP and not being able to make two connections from the same I.P with the same port however I am not sure of this.

I think an alternative solution may be to try and make a connection to the server through UDP instead however I wouldn't be sure how to do this; any insight on an alternative solution would be appreciated.

Here is a snippet of the functioning part of the code that would make a connection with the server to check if it was online.

TCPStartup()
$IP = TCPNameToIP("######.com")
$ServerStatus = TCPConnect($IP, 25565)
If $IP = "" Then
GUICtrlSetData($StatusLabel, "Status: Offline")
EndIf
If $ServerStatus = -1 Then
GUICtrlSetData($StatusLabel, "Status: Offline")
Else
GUICtrlSetData($StatusLabel, "Status: Online")
EndIf
Edited by Venix

Share this post


Link to post
Share on other sites



You use functions named TCP* to connect to the server using TCP. To connect to the server using UDP you should use functions named ...?

Right. UDP*


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You use functions named TCP* to connect to the server using TCP. To connect to the server using UDP you should use functions named ...?

Right. UDP*

However I did not see a function listed as UDPConnect so I was unsure of this because there is a TCPConnect in the help file but no UDP. For this reason I'm not entirely sure which of the UDP functions would carry out the task I require.

Edit: I probably should have stated this in the original post sorry :).

Edited by Venix

Share this post


Link to post
Share on other sites

I would give UDPOpen a try.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Unfortunately this function doesent seem to do what I am after or I'm doing something wrong :) don't know but thanks for helping.

Share this post


Link to post
Share on other sites

TCPConnect: Create a socket connected to an existing server

UDPOpen: Open a socket connected to an existing server

How do you call UDPOpen? Whats the value of @error after the call?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This was my test code and It returns 0 every time even when i have a correct I.P address and port entered. I basically just want to be able to tell if a server is online without it interupting the login of the game. I can't use something as simple as ping which i would like to do because it does not let you use ports :).

UDPStartup()
$IP = TCPNameToIP("#######.com")
$ServerStatus = UDPOpen($IP, 25565)
UDPShutdown()
If $IP = "" Then
MsgBox(64, "Server Status", "Offline")
EndIf
If $ServerStatus = $ServerStatus[0]=0 Then
MsgBox(64, "Server Status", "Offline")
MsgBox(64, "Server Status", $ServerStatus)
Else
MsgBox(64, "Server Status", "Online")
EndIf
Edited by Venix

Share this post


Link to post
Share on other sites

What exactly is this line "If $ServerStatus = $ServerStatus[0]=0 Then" supposed to be doing? UDPOpen returns an array regardless of whether it's successful or not. You can't compare an array against a True/False condition. Also, this line If $IP = "" Then, shouldn't that be done before you try to open the UDP connection so you aren't wasting your time trying to open a connection to an empty IP address? BTW, if the server ever existed, and the DNS record hasn't expired, wouldn't that come back with an IP address even if the server is offline?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

What exactly is this line "If $ServerStatus = $ServerStatus[0]=0 Then" supposed to be doing? UDPOpen returns an array regardless of whether it's successful or not. You can't compare an array against a True/False condition.

I wrote this because I believe it was one of the two returning values that I could have used in the event of an error at least this is what the help file mentioned unless I read it wrong. I could have used @error for this but chose not to at the time.

If $IP = "" Then, shouldn't that be done before you try to open the UDP connection so you aren't wasting your time trying to open a connection to an empty IP address?

Your right, because of the way I coded the script this line turned out useless and I should have added an exit before the end of the IF statement so it did not go on to make the connection and waste time. I did not see this at the time thank you for pointing that out.

BTW, if the server ever existed, and the DNS record hasn't expired, wouldn't that come back with an IP address even if the server is offline?

The game would be hosted with the use of some software and whilst the server software is closed I would not be able to access the port that the server is hosted on however I could still access the I.P itself, this would be the reason why I am not using ping because ping would not allow me to use ports In the command and therefore would always read online.

This is like a pop quiz lol. :graduated:

Edited by Venix

Share this post


Link to post
Share on other sites

I wrote this because I believe it was one of the two returning values that I could have used in the event of an error at least this is what the help file mentioned unless I read it wrong. I could have used @error for this but chose not to at the time.

Use @error or "If $ServerStatus[0]=0 Then", that line isn't ever going to work the way you're trying to make it work.

Your right, because of the way I coded the script this line turned out useless and I should have added an exit before the end of the IF statement so it did not go on to make the connection and waste time. I did not see this at the time thank you for pointing that out.

My point was that if the server has ever been online, and the DNS records haven't expired, then this line "$IP = TCPNameToIP("#######.com")" is going to get the IP address of the server, even if it's offline. So, it's not a check to see if it's on or not.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Ok thanks for the feedback then :).

Share this post


Link to post
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
Sign in to follow this  
Followers 0