H5O2OH Posted June 21, 2008 Share Posted June 21, 2008 (edited) 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 June 21, 2008 by H5O2OH Link to comment Share on other sites More sharing options...
qazwsx Posted June 21, 2008 Share Posted June 21, 2008 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 More sharing options...
H5O2OH Posted June 21, 2008 Author Share Posted June 21, 2008 (edited) ERROR: missing Wend. Edited June 21, 2008 by H5O2OH Link to comment Share on other sites More sharing options...
qazwsx Posted June 21, 2008 Share Posted June 21, 2008 (edited) Ohh sorry, you dont use endif's if you are using one line if statments. I didn't notice that when i copied your code. Edited June 21, 2008 by qazwsx Link to comment Share on other sites More sharing options...
H5O2OH Posted June 21, 2008 Author Share Posted June 21, 2008 (edited) 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 June 21, 2008 by H5O2OH Link to comment Share on other sites More sharing options...
qazwsx Posted June 21, 2008 Share Posted June 21, 2008 (edited) well you are recivieng packets from the string "gay". Put a message box after the recieve to ensure that you are recieving the expected information. Edited June 21, 2008 by qazwsx Link to comment Share on other sites More sharing options...
H5O2OH Posted June 21, 2008 Author Share Posted June 21, 2008 (edited) 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 June 21, 2008 by H5O2OH Link to comment Share on other sites More sharing options...
qazwsx Posted June 21, 2008 Share Posted June 21, 2008 could i see the new code? Link to comment Share on other sites More sharing options...
H5O2OH Posted June 21, 2008 Author Share Posted June 21, 2008 (edited) 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 June 21, 2008 by H5O2OH Link to comment Share on other sites More sharing options...
H5O2OH Posted June 21, 2008 Author Share Posted June 21, 2008 (edited) Here it is working ONLY ONE TIMEDo 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 = 1337Why on earth is that not possible in Autoit Edited June 21, 2008 by H5O2OH Link to comment Share on other sites More sharing options...
H5O2OH Posted June 21, 2008 Author Share Posted June 21, 2008 is the problem in "TCPListen("127.0.0.1", 16675)" Should it be "TCPListen("127.0.0.1", 16675, 100)" ? Please,help! Link to comment Share on other sites More sharing options...
H5O2OH Posted June 21, 2008 Author Share Posted June 21, 2008 Bump >.> Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now