You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"io""os""github.com/akutz/memconn"
)
// ExampleBuffered illustrates a server and client that// communicate over a buffered, in-memory connection.funcmain() {
// Announce a new listener named "localhost" on MemConn's// buffered network, "memb".lis, _:=memconn.Listen("memb", "localhost")
lis2, _:=memconn.Listen("memb", "localhost")
// Ensure the listener is closed.deferlis.Close()
deferlis2.Close()
// Start a goroutine that will wait for a client to dial the// listener and then echo back any data sent to the remote// connection.gofunc() {
conn, _:=lis.Accept()
// If no errors occur then make sure the connection is closed.deferconn.Close()
// Echo the data back to the client.io.CopyN(conn, conn, 13)
}()
// Dial the buffered, in-memory network named "localhost".conn, _:=memconn.Dial("memb", "localhost")
// Ensure the connection is closed.deferconn.Close()
// Write the data to the server.conn.Write([]byte("Hello, world."))
// Read the data from the server.io.CopyN(os.Stdout, conn, 13)
// Output: Hello, world.
}
The text was updated successfully, but these errors were encountered:
Listener with same name will cause panic.
Source Code:
The text was updated successfully, but these errors were encountered: