My original issue is when using splice with io.Copy (example below), for me to regain access to conn, In a different go routine, I use remote.Close() which ends the one of io.Copy commands but, the second io.Copy ends when conn sends a new packet. The error use of closed network connection ends the io.Copy and every new packet conn sends, I can get with conn.Read() but the previous one is lost. I thought may be a multiplexer may help if I hope multiple streams for conn, I can end the splice while still reading all data with conn.Read() with a different stream.
io.Copy(conn, remote) go io.Copy(remote, conn) On Sunday, August 21, 2022 at 5:17:37 AM UTC-4 harald....@gmx.net wrote: > do you even need a multiplexer? The common patten is to run Accept in a > loop that simply starts a new Go routine for every new accepted connection. > You only need a multiplexer of your application protocol needs multiplexing > inside an established TCP connection, either because there are multiple > destinations or multiple streams inside a single connection. > > > On Saturday, August 20, 2022 at 10:31:34 PM UTC+2 ramki...@hotmail.com > wrote: > >> Has anyone ever used a multiplexer <https://github.com/hashicorp/yamux>? >> When creating a TCP server using multiplexer, I get an error [ERR] yamux: >> Invalid protocol version: 102 when using Telnet to connect to the server. >> >> package main >> >> import ( >> "fmt" >> "net" >> >> "github.com/hashicorp/yamux" >> ) >> >> func main() { >> server() >> } >> >> func server() { >> >> listener, _ := net.Listen("tcp", "0.0.0.0:1113") >> 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) >> } >> fmt.Println("DPOO") >> >> // Listen for a message >> buf := make([]byte, 4) >> stream.Read(buf) >> stream.Close() >> session.Close() >> } >> } >> >> -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f2c1c56b-0102-4e88-aa5a-cc7d53fcc953n%40googlegroups.com.