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

  • Konstantin Shaposhnikov at Aug 17, 2015 at 11:52 am
    echo doesn't interpret \n as a new line by default you need to specify -e
    option:

    echo -ne "_e{4,21}:Testing|Testing Hello\n World" | nc -4u -w1 localhost
    8125
    On Monday, 17 August 2015 19:33:10 UTC+8, 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.
  • Milan P. Stanic at Aug 17, 2015 at 12:00 pm

    On Mon, 2015-08-17 at 04:33, DM wrote:
    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:- [...]
    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") [...]
    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?
    Put string in backtick pair, i.e:
    text := `Testing Hello\n World`

    --
    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.
  • Debraj Manna at Aug 17, 2015 at 2:52 pm
    Is there a way I can convert a string to raw string literal? For e.g -
    "Testing Hello\n World" to `Testing Hello\n World`
    On 8/17/15, Milan P. Stanic wrote:
    On Mon, 2015-08-17 at 04:33, DM wrote:
    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:- [...]
    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") [...]
    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?
    Put string in backtick pair, i.e:
    text := `Testing Hello\n World`

    --
    You received this message because you are subscribed to a topic in the
    Google Groups "golang-nuts" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/golang-nuts/sF6FgzgbZ20/unsubscribe.
    To unsubscribe from this group and all its topics, 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.
  • Tamás Gulácsi at Aug 17, 2015 at 3:13 pm
    fmt.Sprintf("%q", x)

    --
    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.
  • Janne Snabb at Aug 17, 2015 at 6:37 pm
    Your interpretation of the tcpdump output is wrong.

    Your go program is sending the newline correctly. tcpdump just displays
    it as a a single dot (.) in the ASCII output the same way as it does for
    all control characters. If you look at the hex output (which you omitted
    from the message) you will see that the newline (0a) is indeed there.

    Your echo command is wrong. It sends a literal "\n" (backslash followed
    by letter n) which tcpdump displays as "\n" (which is not a newline).

    --
    Janne Snabb
    snabb@epipe.com

    On 2015-08-17 14:33, 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:-
    packagemain

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

    func main(){
    conn,err :=net.Dial("udp","127.0.0.1:8125 <http://127.0.0.1:8125>")
    iferr !=nil{
    panic(err)
    }
    varb 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)
    iferr !=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:34a
activeAug 17, '15 at 6:37p
posts6
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase