FAQ
I've been working with simple tcp client/server example ( see attached
files)
If i try to send the message once from the client

conn.Write([]byte("HELLO"))

it works fine and i see server printing out message "HELLO".
If i try to send it multiple times on the existing connection:
for i := 0; i < 50; i++ {
conn.Write([]byte("HELLO"))
}

The server prints out "HELLO" only once, e.g.
server connection handler is called only once. Should't

i be able to reuse connection object without connecting

to server every time?

Thks,

--
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 Jan 28, 2015 at 3:54 pm

    On 28 January 2015 at 15:45, Victor L wrote:
    I've been working with simple tcp client/server example ( see attached
    files)
    If i try to send the message once from the client

    conn.Write([]byte("HELLO"))

    it works fine and i see server printing out message "HELLO".
    If i try to send it multiple times on the existing connection:

    for i := 0; i < 50; i++ {
    conn.Write([]byte("HELLO"))
    }

    The server prints out "HELLO" only once, e.g.
    server connection handler is called only once. Should't

    i be able to reuse connection object without connecting

    to server every time?

    Thks,
    In the code you attached, your handleRequest function
    only does one read, and then exits. If you want to keep
    reading, you have to keep reading ...

    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.
  • Victor L at Jan 28, 2015 at 4:36 pm
    If i have 2 clients writing to it and client1 is finished before client2,

    handleRequest will return EOF even when client2 is still writing messages

    On Wed, Jan 28, 2015 at 10:54 AM, chris dollin wrote:
    On 28 January 2015 at 15:45, Victor L wrote:
    I've been working with simple tcp client/server example ( see attached
    files)
    If i try to send the message once from the client

    conn.Write([]byte("HELLO"))

    it works fine and i see server printing out message "HELLO".
    If i try to send it multiple times on the existing connection:

    for i := 0; i < 50; i++ {
    conn.Write([]byte("HELLO"))
    }

    The server prints out "HELLO" only once, e.g.
    server connection handler is called only once. Should't

    i be able to reuse connection object without connecting

    to server every time?

    Thks,
    In the code you attached, your handleRequest function
    only does one read, and then exits. If you want to keep
    reading, you have to keep reading ...

    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.
  • Vlyamtsev at Jan 28, 2015 at 4:04 pm
    just answering this question: handleRequest should also read in the loop:

    for {

             buf := make([]byte, 1024)

             fmt.Println("read from connection")

             reqLen, err := conn.Read(buf)

             if err != nil {

                 fmt.Println("Error reading:", err.Error())

             }

             fmt.Printf("reqLen=%d ,%s ", reqLen, string(buf))

         }

         conn.Close()


    On Wednesday, January 28, 2015 at 10:45:22 AM UTC-5, Victor L wrote:

    I've been working with simple tcp client/server example ( see attached
    files)
    If i try to send the message once from the client

    conn.Write([]byte("HELLO"))

    it works fine and i see server printing out message "HELLO".
    If i try to send it multiple times on the existing connection:
    for i := 0; i < 50; i++ {
    conn.Write([]byte("HELLO"))
    }

    The server prints out "HELLO" only once, e.g.
    server connection handler is called only once. Should't

    i be able to reuse connection object without connecting

    to server every time?

    Thks,

    --
    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
postedJan 28, '15 at 3:45p
activeJan 28, '15 at 4:36p
posts4
users2
websitegolang.org

2 users in discussion

Vlyamtsev: 3 posts Chris dollin: 1 post

People

Translate

site design / logo © 2021 Grokbase