Jump to content

AutoItOnExit + TCP Question


Recommended Posts

Ok, I am making a authentication script using TCP, anyways I want to send something to the server when AutoIt exits. When a user is logged on, no one else may log back in, but what if there was a power surge? Would the AutoItOnExit occur? :whistle: I'm a bit worried, and your help is highly appreciated, thanks.

Link to comment
Share on other sites

interesting question, you should also wonder what would happen if the computer were to hang / un-expectedly reboot.

perhaps a timeout on the login sessions server side? say.. kick out a user if logged in and in-active for more than XX minutes.

else, allow the user to re-connect to a previous session.

Link to comment
Share on other sites

  • Moderators

Ok, I am making a authentication script using TCP, anyways I want to send something to the server when AutoIt exits. When a user is logged on, no one else may log back in, but what if there was a power surge? Would the AutoItOnExit occur? :whistle: I'm a bit worried, and your help is highly appreciated, thanks.

Is this a twist on logic I hadn't thought of?

Surge Protector

Back Up Battery's

Generator

I mean, if you cut power completely off to something without any back up setup, what do you think happens?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

interesting question, you should also wonder what would happen if the computer were to hang / un-expectedly reboot.

perhaps a timeout on the login sessions server side? say.. kick out a user if logged in and in-active for more than XX minutes.

else, allow the user to re-connect to a previous session.

I have no idea how to make a session.. I guess I could try. Well the user list is held on the servers computer, so I could use TCPCloseSocket() with timerint() or so on the server, and make a function (for the client) so if the socket is closed, it goes back to the login screen... and when another user logs in (If the IP is different) it kicks the other person off... WELL... maybe I DO know how to make a session now =D

And Smoke_N... I guess your right, But I think the method where if the user logs back in and the IP isn't different, they are allowed back in. Hopefully this method will work.. tell me what you think.

Link to comment
Share on other sites

  • Moderators

If you want to see kind of what would happen.

  • Compile the script provided here
  • Run Script
  • If you have a "reset" button, click "reset" on your PC
  • If no "reset": Ctrl + Alt + Delete >> Shut Down >> While holding down the Ctrl button click Restart
Now if you exit with the ESC button it will log you escaped with Hotkey, if you exited by any other means, it will log that you exited by another means.

To me what you are asking, is just like killing the process via Task Manager or proceexp.exe, it doesn't allow your executable to finish doing anything else.

HotKeySet('{ESC}', '_ExitNow')

While 1
    Sleep(1000000)
WEnd

Func _ExitNow()
    Exit -4
EndFunc

Func OnAutoItExit()
    If @exitCode = -4 Then
        FileWrite('TestExit.log', 'Exit By Hotkey: ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF)
    Else
        FileWrite('TestExit.log', 'Exit By Other Means: ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF)
    EndIf
EndFunc

I think that you should just script on the client to note that the server may be down. Then upon startup, make sure your server is in the startup folders. Have it do a check when signed in on how it was last exited. If it wasn't exited and logged by whatever way you want (can be set as you can set Exit -1 or Exit -2 or whatever), then it should allow those people to re-connect.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Eh, my method helps me with a bunch of other scripts, but thanks for the little test script. But i need a bit more help. Could someone help me with the function to see if the user is connected to a socket? Let's say on the server, they were afk, and the server used TCPCloseSocket(), is there a function I could put in a loop to see if they are connected to a socket?

Link to comment
Share on other sites

  • Moderators

Eh, my method helps me with a bunch of other scripts, but thanks for the little test script. But i need a bit more help. Could someone help me with the function to see if the user is connected to a socket? Let's say on the server, they were afk, and the server used TCPCloseSocket(), is there a function I could put in a loop to see if they are connected to a socket?

You're questions are confusing.

TCPCloseSocket() and you are done period.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Sorry i'll try to explain as best I can ><:

So after the server Closes the socket, I want the client to do a certain thing. How do I tell the client the Socket is Closed and to go do that certain thing?

If TCPCloseSocket() Then
;Whateer
EndIf

Is this it?

Link to comment
Share on other sites

  • Moderators

Sorry i'll try to explain as best I can ><:

So after the server Closes the socket, I want the client to do a certain thing. How do I tell the client the Socket is Closed and to go do that certain thing?

If TCPCloseSocket() Then
;Whateer
EndIf

Is this it?

Hadn't really thought of it to be honest, I always send data to the Client telling it I'm about to shut it off and to run whatever protocol I had programmed into it personally.

Maybe:

$sData = TCPReceive($nSocket, $nCharLen)
If @error Then ;Server has disconnected
    ;Do whatever
EndIf
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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