FAQ
_, error := connection.Read(buffer)
buffer := make([]byte, BUFFER_SIZE)
splited := strings.Split(string(buffer), " ")switch splited[0] {case "TEST":
     connection.Write([]byte("TEST CONNECTION OK"))
     log.Printf("TEST COMMAND")
     break;

If I write "TEST" in client, the server will not enter the case statement. But if I send "TEST SOMETHING" from client, the server will enter the case as expected. Is this a bug of go-lang?

I printed splited[0]+"aaa" and it's just "TESTaaa", nothing seems wrong. Also tested with if splited[0] == "TEST", all failed

--
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

  • Chris dollin at Nov 24, 2014 at 1:49 pm

    On 24 November 2014 at 13:25, Thomas King wrote:
    _, error := connection.Read(buffer)
    buffer := make([]byte, BUFFER_SIZE)
    You've thrown away the original value of buffer, ignored
    any error on the read, and you don't know how many bytes it
    read. Are you sure this is the code you used?
    splited := strings.Split(string(buffer), " ")
    If the buffer has null bytes after the string that was sent
    (easily possible), then you will have null bytes in the string
    and they'll almost certaibnly not print visibly.
    switch splited[0] {
    case "TEST":
    connection.Write([]byte("TEST CONNECTION OK"))
    log.Printf("TEST COMMAND")
    break;

    If I write "TEST" in client, the server will not enter the case statement.
    But if I send "TEST SOMETHING" from client, the server will enter the case
    as expected.
    If you write TEST in the client there will be null bytes following
    TEST. If you write TEST SOMETHING, the null bytes will come
    after SOMETHING and TEST won't have them.
    Is this a bug of go-lang?
    No.

    Chris

    --
    Chris "allusive" Dollin

    --
    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 Nov 24, 2014 at 1:53 pm
    Print out the splited[0] value verbatim. It contains null bytes:

    []string{"TEST\x00\x00\x00\x00\x00\...


    On Monday, November 24, 2014 8:25:55 AM UTC-5, Thomas King wrote:

    _, error := connection.Read(buffer)
    buffer := make([]byte, BUFFER_SIZE)
    splited := strings.Split(string(buffer), " ")switch splited[0] {case "TEST":
    connection.Write([]byte("TEST CONNECTION OK"))
    log.Printf("TEST COMMAND")
    break;

    If I write "TEST" in client, the server will not enter the case statement. But if I send "TEST SOMETHING" from client, the server will enter the case as expected. Is this a bug of go-lang?

    I printed splited[0]+"aaa" and it's just "TESTaaa", nothing seems wrong. Also tested with if splited[0] == "TEST", all failed
    --
    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.
  • Thomas King at Nov 24, 2014 at 2:18 pm
    Thank you all! I got the same answer on irc channel, sorry for bothering

    --
    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
postedNov 24, '14 at 1:25p
activeNov 24, '14 at 2:18p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase