Jump to content

Regarding TCP Do <-> Until


Recommended Posts

Hey,

So this is the script I've got from the example scripts section:

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 smile.gif")

I don't need the login system,but my problem is that it closes the socket if login information doesn't match or ,because if login match,it doesnt check anymore. :)

In other words,if i start client.exe and enter admin/password it says "Connected",then if i do it again it says "cannot connect to server".

How can I make it always check the socket?

Example of what i want

Do
            Sleep(100)
            $TEMP = TCPRecv($SOCKET, 256)
        Until $TEMP <> ""

if $TEMP = "Hello" Then TCPSend($Socket,"hey!")
EndIF
IF $Temp = "What's up?" Then TCPSend($Socket,"Nothing much,you?").
EndIf

I guess you get it,I want to keep the connection alive,without closing the socket and I want to send packet after packet,for example,first it checks if the client says "hello" then server says "hey",then the client says "whats up?" and then the server reply "Nothing much,you?".

Thank you in advance.

Edited by H5O2OH
Link to comment
Share on other sites

In other words,if i start client.exe and enter admin/password it says "Connected",then if i do it again it says "cannot connect to server".

It cannot connect to the server because the socket is already being used by the first client. Add ur code to the server code. The server is closing because the script is finishing. Also change ur topic title to something that describes your problem. Use a while loop if you want the server to check for information forever.

While 1
            Sleep(100)
            $TEMP = TCPRecv($SOCKET, 256)       

if $TEMP = "Hello" Then TCPSend($Socket,"hey!")
EndIF
IF $Temp = "What's up?" Then TCPSend($Socket,"Nothing much,you?").
EndIf
Wend
Link to comment
Share on other sites

That's the problem!

Do
    Sleep(10)
    $socket = TCPAccept($listen)
    If $socket <> -1 Then
       While 1
            $Check1="A7416363"; Login Packet.
            Sleep(100)
            $TEMP = TCPRecv($SOCKET, 256)       
            if StringLeft($TEMP, 4) = _HexToString($Check1) Then Msgbox(0,"title","We've got Loggin packet!")
            if $Temp = "What's up?" Then TCPSend($Socket,"Nothing much,you?")
        Wend
        If StringLeft($temp, 4) = _HexToString($Check1) Then
            Msgbox(0,"title","We've got Loggin packet!")
            TcpCloseSocket($Socket)
            $socket = -1
        Else
            TcpCloseSocket($Socket)
            $Socket = -1
        EndIf
    EndIf
Until $Socket <> -1

No error,but it shows the msg only one time,while it gets the packet always! :)

Edited by H5O2OH
Link to comment
Share on other sites

I removed the gay string,even if i change the packet to "hello" it does show it only one time!

I'm sure it does receive it again,because i see it in wpepro,but the server accept it only one time,thats the problem! :)

Edited by H5O2OH
Link to comment
Share on other sites

Sure,I used two while now.

TCPStartup()
$listen = TCPListen("127.0.0.1", 16675)

While 1
    Sleep(10)
    $socket = TCPAccept($listen)
    If $socket <> -1 Then
       While 1
            $Check1="A7416363"; Login Packet.
            Sleep(100)
            $TEMP = TCPRecv($SOCKET, 256)       
            if StringLeft($TEMP, 4) = _HexToString($Check1) Then Msgbox(0,"title","We've got Loggin packet!")
            if $Temp = "What's up?" Then TCPSend($Socket,"Nothing much,you?")
        Wend
    EndIf
Wend

Result-> it shows the msg only first time,next time i send it,nothing but client is still connected.

Edited by H5O2OH
Link to comment
Share on other sites

Here it is working ONLY ONE TIME

Do
    Sleep(10)
    $socket = TCPAccept($listen)
    $TEMP = TCPRecv($SOCKET, 256)   
    If $socket <> -1 Then
    $Check1="A7416363"; Login Packet
       While 1
            $TEMP = TCPRecv($SOCKET, 22256)
            $Check1="A7416363"; Login Packet
        ;msgbox(0,"",$TEMP);used to check the Received packet and it is the same,but it shows the msg only one time!
            if $TEMP = "Hello" Then Msgbox(0,"title","We've got Loggin packet!")
            if $Temp = "What's up?" Then TCPSend($Socket,"Nothing much,you?")
        Wend
    EndIf
Until $Check1 = 1337

Why on earth is that not possible in Autoit :)

Edited by H5O2OH
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...