FAQ
Hello!
The error "slice bounds out of range" appears When i try to send multiple
requests to the server from the client. for the first requests, every thing
is fine
this is the code that causes the error:

for client.ReadClient(buffer) {

// Check for STX and ETX
posSTX := bytes.IndexByte(buffer, 0x02)
if(posSTX==-1){
return
}

posETX := bytes.IndexByte(buffer, 0x03)
if(posETX==-1){
return
}
         Log("posSTX ",posSTX)
         Log("posETX ",posETX)


msg := string(buffer[posSTX+1:posETX-posSTX])
}

i try in this code to extract the char "0x02" and "0x03" that delimit the
  received message.
but sometimes posSTX is bigger than posETX that's what causes the error
"posSTX+1:posETX-posSTX"
anyone has an idea why it's correct for the first requests and not for the
rest??? what can be the solution for this??

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Tamás Gulácsi at Apr 9, 2014 at 4:17 pm
    In the slice a[i:j], j>i because j is an index, not length! Thus you need msg[posStx+1:posEtx].

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Farah at Apr 10, 2014 at 8:32 am
    Thank you Tamas,
    but I tried it, it's the same error , the problem is that posSTX+1> posETX
    posETX-posSTX, it's an interval it can't resolve the problem !
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Tamás Gulácsi at Apr 10, 2014 at 6:29 pm
    Create a working example on play.golang.org

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • James Bardin at Apr 10, 2014 at 6:44 pm

    On Thursday, April 10, 2014 4:32:15 AM UTC-4, farah wrote:
    Thank you Tamas,
    but I tried it, it's the same error , the problem is that posSTX+1>
    posETX >posETX-posSTX, it's an interval it can't resolve the problem !
    I think you might be misunderstanding slice notation -- why are you
    subtracting STX from ETX? That's going to invert the relative sizes of the
    values once STX is larger than the message size.

    Just use [posSTX+1:posETX].

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Zhengkang727 at Apr 15, 2014 at 3:12 pm
    I think,you can do the Swap(posStx,posExt) to make the posExt is bigger,
      buffer[posStx+1:posExt] is not include the data buffer[posStx]

    在 2014年4月9日星期三UTC+8下午11时55分43秒,farah写道:
    Hello!
    The error "slice bounds out of range" appears When i try to send multiple
    requests to the server from the client. for the first requests, every thing
    is fine
    this is the code that causes the error:

    for client.ReadClient(buffer) {

    // Check for STX and ETX
    posSTX := bytes.IndexByte(buffer, 0x02)
    if(posSTX==-1){
    return
    }

    posETX := bytes.IndexByte(buffer, 0x03)
    if(posETX==-1){
    return
    }
    Log("posSTX ",posSTX)
    Log("posETX ",posETX)


    msg := string(buffer[posSTX+1:posETX-posSTX])
    }

    i try in this code to extract the char "0x02" and "0x03" that delimit the
    received message.
    but sometimes posSTX is bigger than posETX that's what causes the error
    "posSTX+1:posETX-posSTX"
    anyone has an idea why it's correct for the first requests and not for the
    rest??? what can be the solution for this??
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 9, '14 at 3:55p
activeApr 15, '14 at 3:12p
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase