FAQ
Hi,

I have a udp server running at port 8125 in localhost. I am trying to
submit a udp message to the udp server with the below code:-

package main

import (
     "bytes"
     "fmt"
     "net"
     "unicode/utf8"
)

func main() {
     conn, err := net.Dial("udp", "127.0.0.1:8125")
     if err != nil {
         panic(err)
     }
     var b bytes.Buffer
     title := "Testing"
     text := "Testing Hello\n World"
     fmt.Fprintf(&b, "_e{%d,%d}:%s|%s|t:%s", utf8.RuneCountInString(title),
         utf8.RuneCountInString(text), title, text, "error")
     fmt.Fprintf(&b, "|s:%s", "test")
     bytes := b.Bytes()
     _, err = conn.Write(bytes)
     if err != nil {
         panic(err)
     }
     fmt.Println("Message Submitted")
}

If I do a tcpdump on the port 8125 with the below command:-

sudo tcpdump -i lo udp port 8125 -vv -X

The payload looks like:-

_e{7,20}:Testing|Testing.Hello..World|t:error|s:test

The \n is missing.

If I submit the message directly with the below command:-

echo -n "_e{4,21}:Testing|Testing Hello\n World" | nc -4u -w1 localhost 8125

The payload in tcpdump looks like the below with the new line showing up.

_e{4,21}:Testing|Testing.Hello\n.World

Can some one let me know why is this difference? How can I prevent the \n
being getting dropped?

Thanks,

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

  • Matt Harden at Aug 17, 2015 at 9:29 pm
    The newline is not getting dropped. In your echo example, echo is not
    interpreting the \n as a newline; it's printing it as a literal backslash
    and the letter n. You should pass "-e" to echo to get the newline. Tcpdump
    is printing the newline as a dot, just as it does with spaces. Notice that
    there are two dots between "Hello" and "World"; the first is the newline
    and the second is the space before "World". Pass -XX to tcpdump to also get
    a hex dump of the data. You should see "0d", the ASCII code for newline, in
    the hex dump.
    On Mon, Aug 17, 2015 at 6:35 AM DM wrote:

    Hi,

    I have a udp server running at port 8125 in localhost. I am trying to
    submit a udp message to the udp server with the below code:-

    package main

    import (
    "bytes"
    "fmt"
    "net"
    "unicode/utf8"
    )

    func main() {
    conn, err := net.Dial("udp", "127.0.0.1:8125")
    if err != nil {
    panic(err)
    }
    var b bytes.Buffer
    title := "Testing"
    text := "Testing Hello\n World"
    fmt.Fprintf(&b, "_e{%d,%d}:%s|%s|t:%s", utf8.RuneCountInString(title),
    utf8.RuneCountInString(text), title, text, "error")
    fmt.Fprintf(&b, "|s:%s", "test")
    bytes := b.Bytes()
    _, err = conn.Write(bytes)
    if err != nil {
    panic(err)
    }
    fmt.Println("Message Submitted")
    }

    If I do a tcpdump on the port 8125 with the below command:-

    sudo tcpdump -i lo udp port 8125 -vv -X

    The payload looks like:-

    _e{7,20}:Testing|Testing.Hello..World|t:error|s:test

    The \n is missing.

    If I submit the message directly with the below command:-

    echo -n "_e{4,21}:Testing|Testing Hello\n World" | nc -4u -w1 localhost
    8125

    The payload in tcpdump looks like the below with the new line showing up.

    _e{4,21}:Testing|Testing.Hello\n.World

    Can some one let me know why is this difference? How can I prevent the \n
    being getting dropped?

    Thanks,

    --
    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.
    --
    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
postedAug 17, '15 at 11:30a
activeAug 17, '15 at 9:29p
posts2
users2
websitegolang.org

2 users in discussion

DM: 1 post Matt Harden: 1 post

People

Translate

site design / logo © 2021 Grokbase