6 Replies Latest reply on Jun 9, 2010 3:06 PM by SOMEONEINTHEWORLD





      The below code works fine.  It checks for vertical tab -13, i want it to detect the "EOF" string.  Can anyone tell me how to make it to detect "EOF"?


      try {
                          for(var i:uint=1;i<readBuf.length;++i) {
                              if(readBuf[i-1]=="13") {
                                  var newBuf:ByteArray=new ByteArray();
                                      new CustomEvent(
                                          readBuf.readUTFBytes(i).substr(0,-1), readBuf
                      } catch (excpt:EOFError) {}



        • 1. Re: DETECTING EOF
          oldMster Level 3

          What is the 'EOF' string?  is it the characters EOF in sequence? Or are you expecting a particular character (like ascii 13 for line terminator)?

          There is no predefined EOF character, so the file you are sending either needs to be 'framed', or perhaps the socket disconnects after it sends the last bit of the file, in which case you need to listen for the close event.


          • 2. Re: DETECTING EOF
            SOMEONEINTHEWORLD Level 1

            it is in the format,


            file_content + "EOF"


            EOF is a string attached before sending

            • 3. Re: DETECTING EOF
              oldMster Level 3

              The problem you will have is that there is no guarantee that EOF won't be split across multiple ProgressEvent.SOCKET_DATA events, so you are going to need a way to keep track of that.

              I don't use ByteArrays much, so if the 69 (E), etc. needs to be changed do so.  I'm assuming the "13" is representing carriage return

              I would have a 'above the line' String variable to keep track of it and do something like this


              'above the line' variable:


              var checkEOF:String = "";


              try {
                                  for(var i:uint=1;i<readBuf.length;++i) {

                                      if (checkEOF == "" && (readBuff[i-1]=="69")) {

                                                 checkEOF = "E";


                                       else if (checkEOF == "E" && (readBuff[i-1]=="79")) {

                                                 checkEOF = "EO";


                                       else if (checkEOF== "EO" && (readBuff[i-1]=="70")) {

                                            //do whatever you need to do when EOF is encountered


                                       else {

                                            //since this isn't part of EOF, clear the EOF variable


                                      if(readBuf[i-1]=="13") {

              • 4. Re: DETECTING EOF
                GordonSmith Level 4

                > file_content + "EOF"


                That sounds like a bad idea. What are you going to do if the content contains "EOF"? For example, the content "GEOFFREY CHAUCER" would get cut down to "G". Don't you want to use a special control character that isn't going to be in the content?


                Gordon Smith

                Adobe Flex SDK Team

                • 5. Re: DETECTING EOF
                  SOMEONEINTHEWORLD Level 1



                  That is what i wanted.

                  • 6. Re: DETECTING EOF
                    SOMEONEINTHEWORLD Level 1

                    Pretty bad idea.  I am not coding the server.  If i was i would have used a single character like vertical tab 13.