annelinn Posted April 18, 2009 Share Posted April 18, 2009 Hello all, I'm trying to learn about TCP and have written a simple server/client program. 1. Client connects to server 2. Server acknowledges connection 3. Client encrypts a short message using the rijndael cipher 4. Client sends the message to the server 5. Server decrypts the message, and displays it 6. Steps 3-5 repeat ten times at random intervals Now, the problem is this. The following code works just fine: For $a = 1 to 10 Sleep(Random(3000, 5000)) TCPSend($Socket, Encrypt($message)) ; Send the message Next But, if you try to send multiple packets at almost same time (as in the next example), some of them are received by the server correctly, but some are received as gibberish! For $a = 1 to 10 Sleep(Random(3000, 5000)) TCPSend($Socket, Encrypt($message)) ; Send the message Sleep(500) TCPSend($Socket, Encrypt($message & " Version 2")) ; Send the message with some text appended Next I don't understand! Have I missed something obvious, or is AutoIT incapable of sending more than one packet a second? Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 18, 2009 Share Posted April 18, 2009 Are you sure that the server is decrypting a complete message? Link to comment Share on other sites More sharing options...
annelinn Posted April 18, 2009 Author Share Posted April 18, 2009 (edited) Are you sure that the server is decrypting a complete message?I think it is confusing two messages as one, and trying to decrypt them both as a single message. Example: message 26732 is sent twice, and decrypted twice Example: next message, 30414, is sent twice, but decrypted once, and the decrypted text is garbled The question is: does TCPReceive() receive both messages, and confuse them as one? (below is the code from the server) $data = TCPRecv($socket, 512) $result = Decrypt($data) ; Display the decrypted message _GUICtrlEdit_AppendText($window, $result & @CRLF) Edited April 18, 2009 by annelinn Link to comment Share on other sites More sharing options...
trancexx Posted April 18, 2009 Share Posted April 18, 2009 Or client encrypting properly? This is totally off topic but why using that ugly 'win classic' style? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
annelinn Posted April 18, 2009 Author Share Posted April 18, 2009 (edited) Or client encrypting properly? This is totally off topic but why using that ugly 'win classic' style?I'm as sure as I can be that the encrypting algorithm is correct, because I'm using the one skinnywhiteguy wrote (rijndael.au3): http://www.autoitscript.com/forum/index.php?showtopic=44581 And my implementations are: Func Encrypt($message, $key)) Return StringToBinary(_rijndaelCipher($key, $message)) EndFunc and Func Decrypt($message, $key) Return BinaryToString(_rijndaelInvCipher($key, $message)) EndFunc About ugly windows themes: one ugly theme is much the same as any other Edited April 18, 2009 by annelinn Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 18, 2009 Share Posted April 18, 2009 (edited) How about adding an integer value of the length of the message before sending it. Then have the server read the length value, and pick up that many bytes for the message. That way you know you only have one message at a time. Like client: encrypt "something"->"237841" client: send 6 client: send "237841" server: read incoming, get a 6 server: read 6 bytes server: decrypt "237841"->"something" Edited April 18, 2009 by Richard Robertson Link to comment Share on other sites More sharing options...
annelinn Posted April 19, 2009 Author Share Posted April 19, 2009 An excellent idea. Despite it being so obvious, it never occured to me. Thanks! 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