Sign in to follow this  
Followers 0
Hest

Stop program from closing

6 posts in this topic

#1 ·  Posted (edited)

I found this little code for a server that receives a username and password and sends back an OK. After that the program closes.

How can I make the program continue and start over? I want it to stay in the background and listen for another "login" over and over.

Its the SERVER kode on this page http://www.autoitscript.com/forum/index.ph...mp;#entry530049

; Server (Start first)
TCPStartup()
$listen = TCPListen("127.0.0.1", 2111)
Global $username = "admin", $password = "password"
Global $loggedin = False
Do
    Sleep(10)
    $socket = TCPAccept($listen)
    If $socket <> -1 Then
        Do
            Sleep(100)
            $temp = TCPRecv($socket, 256)
        Until $temp <> ""
        $array = StringSplit($temp, "|")
        If $array[1] == $username And $array[2] == $password Then
            TCPSend($socket, "Connected")
            $loggedin = True
        Else
            TCPSend($socket, "Connection failed")
            TCPCloseSocket($socket)
            $socket = -1
        EndIf
    EndIf
    
Until $socket <> -1
MsgBox(0,"Success","Someone connected ")
Edited by Hest

Software:Model Train Calculator (Screen)Autoit3 beginner!

Share this post


Link to post
Share on other sites



Cool my code muttley

Don't have time to test, but try change "Until $socket <> -1" To "Until False". It should work :)

And of course, move the MessageBox to the line under $loggedin=True if you still want the visual confirmation :(

Good Luck!


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Thx alot, I'll give it a try later today. Hope it works, or I'll be back muttley


Software:Model Train Calculator (Screen)Autoit3 beginner!

Share this post


Link to post
Share on other sites

Just tested it and it works muttley Thx

Now I can continue working on my program


Software:Model Train Calculator (Screen)Autoit3 beginner!

Share this post


Link to post
Share on other sites

Maybe you could help me a little bit more. Sometimes the server stops responding, do you have any idear how to fix that or what the reason could be?

It can be after 10 sec or a couple of minutes. Is it possible to make it responde again somehow?


Software:Model Train Calculator (Screen)Autoit3 beginner!

Share this post


Link to post
Share on other sites

I would change the Sleep(10) to a more forgiving number of 250 500 750 1000 to be less fearful of CPU usage


Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

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