Jump to content

mb2

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by mb2

  1. Well I think finaly got it working. Changed back again to your original code and if a send a few packets, no problem but when sending lots of packets then somehow on every packet i mis one character. Maby i'm doing something wrong or i don't understand how correctly split the data. After making a few minor changes it finaly worked for me. Global $PacketEndTag = "<END>" Global $PacketEndTagLen = StringLen($PacketEndTag) check() $sRecv = StringLeft($Clients[$i][3], StringInStr($Clients[$i][3], $PacketEndTag, 1, -1) -1) $Clients[$i][3] = StringTrimLeft($Clients[$i][3], StringLen($sRecv) + ($PacketEndTagLen + 0)) ;instead of +1 use the lengt of the packet endtag, this puls the full packet from buffer. Instead using @CR changed to a variable, makes it more easy for testing and to customise endtag but maby bad for performance ? But most important change for me is on the second line + 0, instead of +1, now this pulls the complete packet including the endtag. This way it is possible to split complete packets using stringsplit function, without losing a character on every packet even when buffer is filling up. I test this using telnet and copy past a file containing lots of bugus data '01234567890<END>' Anyhow I like your code but maby a few small changes makes it a bit more easy to work with, you don't want to know how much time it cost me
  2. I could not figure out how to receive complete packets without this change ?
  3. Tnx for this code, will be using this! But as Lecarre said before, the following should be changed. #1 $sRecv = StringLeft($Clients[$i][3], StringInStr($Clients[$i][3], @CRLF, 0, -1)) ;Pull all data to the left of the last @CRLF in the buffer Pulls on the last CRLF, should pull the first, when it recieved both login and password it pulled both. Should Pull only 1 at a time. Fixed Changed -1 to 1 #region ;Example message processing stuff here. This is handling for a simple "echo" server While 1 ; While Messages are found $sRecv = StringLeft($Clients[$i][3], StringInStr($Clients[$i][3], @CRLF, 0, 1)) ;Pull all data to the left of the First @CRLF in the buffer If $sRecv = "" Then ExitLoop ;Check if there were any complete "messages" $Clients[$i][3] = StringTrimLeft($Clients[$i][3], StringLen($sRecv) +1 ) ;remove what was just read from the client's buffer TCPSend($Clients[$i][0], "Echo: " & $sRecv & @CRLF) ;Echo back what the client sent wend #endregion ;Example Using -1 will give problems when reveiving multiple packets from the buffer.
×
×
  • Create New...