NewOneOffMuxConn wraps a raw conn as a mux.Stream to access a rpc/mux.Server. Combine this with rpc.NewClient: Dial conn with a corresponding dialer of RPC server Wrap conn as stream with NewOneOffMuxConn Call rpc.NewClient(stream) to get client.
(conn net.Conn)
| 178 | // Wrap conn as stream with NewOneOffMuxConn |
| 179 | // Call rpc.NewClient(stream) to get client. |
| 180 | func NewOneOffMuxConn(conn net.Conn) (net.Conn, error) { |
| 181 | sess, err := mux.Client(conn, mux.DefaultConfig()) |
| 182 | if err != nil { |
| 183 | return nil, errors.Wrapf(err, "create session to %s", conn.RemoteAddr()) |
| 184 | } |
| 185 | stream, err := sess.OpenStream() |
| 186 | if err != nil { |
| 187 | return nil, errors.Wrapf(err, "open stream to %s", conn.RemoteAddr()) |
| 188 | } |
| 189 | return &oneOffMuxConn{ |
| 190 | Stream: stream, |
| 191 | sess: sess, |
| 192 | }, nil |
| 193 | } |
| 194 | |
| 195 | // GetEx returns an one-off connection if it's anonymous, otherwise returns existing session |
| 196 | // with Get. |