Sign in to follow this  
Followers 0
Venix

Help me with TCPConnect

6 posts in this topic

I am trying to create an application that will let me know if a friend’s Minecraft server is online, it will achieve this by trying to connect to the server and if it receives an error then it will change the label accordingly. Unfortunately the code I tried to connect to the server is always returning an error and displaying offline, I'm not quite sure what I am doing wrong as this is the first time I’ve tried to use a TCP connection in a program.

Please note that I am only trying to connect to an I.P and it has nothing to do with game automation.

Thanks for any help.

$ServerStatus = TCPConnect("randomserver.net", 25565)
If $ServerStatus = -1 Then
GUICtrlSetData($StatusLabel, "Status: Offline")
Else
GUICtrlSetData($StatusLabel, "Status: Online")
EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

maybe you forgot

TCPStartup()

BTW i'm not even good in this remote stuff

But then too I think

Ping
might be more useful Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

I tried adding TCPStartup() Before my TCP command recently with no luck, and although ping is useful it wont allow me to assign a port which is important.

Thanks for the help though.

Share this post


Link to post
Share on other sites

This works for me

Opt ('TrayIconDebug',1)
; Start The TCP Services
;==============================================
TCPStartup()
;Convert Website to IP
Local $g_IP = TCPNameToIP("www.autoitscript.com")
If @error Then
MsgBox(16,'Unable To Connect','Wrong Server Address')
Exit TCPShutdown()
EndIf


; Connect to Port 80
;==============================================
Local $socket = TCPConnect($g_IP, 80)
Switch $socket
Case -1
MsgBox(16,'Unable To Connect','ReturnCode: '&$socket)
Case Else
MsgBox(64,'Connection Successful','Socket Identifier: '&$socket)
EndSwitch

TCPShutdown()

If doesnt help then

Can you give the Server Address and the Port Number

Regards

Phoenix XL


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This worked fine Pheonix thank you, the problem was that I didnt use TCPNameToIP.

Edited by Venix

Share this post


Link to post
Share on other sites

Opt ('TrayIconDebug',1)
; Start The TCP Services
;==============================================
TCPStartup()
;Convert Website to IP
Local $g_IP = TCPNameToIP("www.autoitscript.com")
If @error Then
MsgBox(16,'Unable To Connect','Wrong Server Address')
Exit TCPShutdown()
EndIf


; Connect to Port 80
;==============================================
Local $socket = TCPConnect($g_IP, 80)
Switch $socket
Case -1
MsgBox(16,'Unable To Connect','ReturnCode: '&$socket)
Case Else
MsgBox(64,'Connection Successful','Socket Identifier: '&$socket)
EndSwitch

TCPShutdown()

Phoenix XL

Someone add this to the Snippets !

A true renaissance man

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