Jump to content

AdlibRegister


Recommended Posts

I've got a function that get's called every 5-10 seconds. As soon as it does - the program starts lagging. Is the problem in the function itself or...?

Function:

AdlibRegister ("Connect", 5000)

Func Connect ()
If $TCPConnect = -1 Then
  $TCPConnect = TCPConnect ("ip", port)
  If not @error Then
   If $State = 1 Then
    $title=WinGetTitle ("NAME - NAME1")
    $title = StringSplit ($title, " - ", 1)
    If not @error and $title [0] > 1 Then
     $nick=$title[2]
     TCPSend ($TCPConnect, "nick="&$nick)
    EndIf
   Else
    TCPSend ($TCPConnect, "closed")
   EndIf
  EndIf
EndIf
EndFunc
Link to comment
Share on other sites

I'm sure it's the function. The main script is paused every 5 seconds to run the function and waits till the function has finished.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

What your function does is it checks the $TCPConnect variable and if you're not connected ($TCPConnect = -1), it tries to connect; if it can't connect it's going to sit there waiting until it times out.

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

Link to comment
Share on other sites

There's a bug report on the Tracker reporting that the option for TCPTimeout doesn't seem to do anything, looks like it takes about 20 seconds before it times out and throws an error message back.

EDIT: I found that JScript started, and ProgAndy added to, that has an alternate TCPConnect that includes a timeout parameter that might work better for you than the built-in TCPConnect.

Edited by BrewManNH

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

Link to comment
Share on other sites

There's a bug report on the Tracker reporting that the option for TCPTimeout doesn't seem to do anything, looks like it takes about 20 seconds before it times out and throws an error message back.

EDIT: I found that JScript started, and ProgAndy added to, that has an alternate TCPConnect that includes a timeout parameter that might work better for you than the built-in TCPConnect.

I think that worked! I don"t know what the function does but i've plugged it in and it seems to not slow down anything. Thank you

Link to comment
Share on other sites

No it didn't. _TCPConnect returns values other than -1 even when the server is offline.

What I am trying to do is this:

I want my script every so often to try and connect to the server. Every 60 seconds for example. If the server is offline then try again in 60. Whats the best way to do this?

Link to comment
Share on other sites

What is it returning other than -1 when it's offline?

Because when I run it with TCPConnect or with _TCPConnect from the link, I'm getting -1 on a non-existant server and it returns, for me at least, in under a millisecond. This is on Windows 7 x64, trying to "connect" to one of yahoo's webserver IP addresses.

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

Link to comment
Share on other sites

It returns 468 for me when the server is offline

The server is offline

$ip="ip"

$port=port

$timeout=500

$TCPConnect = _TCPConnect ($ip, $port, $timeout)

ConsoleWrite ($TCPConnect&@CRLF)

The console displays 468

Edited by tsolrm
Link to comment
Share on other sites

I've opened my current connections using TCPView

Even though the server script is not running - this function connects to the port but the connection dissapears after 20 seconds. I'm not sure how is it doing it cos the server is not listening on that port.

Edited by tsolrm
Link to comment
Share on other sites

Please post your script so that we can figure out where it's going wrong, because I can't duplicate your problem using anything I've tried.

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

Link to comment
Share on other sites

Maybe because you haven't opened your port for listening and haven't set up port forwarding.

$ip="ip"

$port=port

$timeout=500

$TCPConnect = _TCPConnect ($ip, $port, $timeout)

ConsoleWrite ($TCPConnect&@CRLF)

thats it basically. TCPConnect returns a value different to -1 because it does in fact connect to the port (for about 20 seconds or so) and then the connection is abandoned. I've checked this with TCPView

Link to comment
Share on other sites

So it's not failing, it's connecting to the port that you have opened, it's just not telling you there's no server there.

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

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