hashicorp / yamux

Golang connection multiplexing library
Mozilla Public License 2.0
2.19k stars 232 forks source link

Protocol Version Error #111

Closed da-tai closed 1 year ago

da-tai commented 2 years ago

I don't think I fully understand something. I telnet to code below but I get the error [ERR] yamux: Invalid protocol version: 102. What exactly is wrong?

Here is my code


import (
    "net"
    "github.com/hashicorp/yamux"
)

func main() {
    server()
}

func server() {

    listener, _ := net.Listen("tcp", "0.0.0.0:1234")
    for {

        // Accept a TCP connection
        conn, err := listener.Accept()
        if err != nil {
            panic(err)
        }

        // Setup server side of smux
        session, err := yamux.Server(conn, nil)
        if err != nil {
            panic(err)
        }

        // Accept a stream
        stream, err := session.Accept()
        if err != nil {
            panic(err)
        }

        // Listen for a message
        buf := make([]byte, 4)
        stream.Read(buf)
        stream.Close()
        session.Close()
    }
}
hayden-pan commented 2 years ago

This is not the correct usage, when the server is yamux, then the client must be yamux. Please checkout the README.md