MCPcopy Create free account
hub / github.com/CPChain/chain / DialWebsocket

Function DialWebsocket

api/rpc/websocket.go:126–146  ·  view source on GitHub ↗

DialWebsocket creates a new RPC client that communicates with a JSON-RPC server that is listening on the given endpoint. The context is used for the initial connection establishment. It does not affect subsequent interactions with the client.

(ctx context.Context, endpoint, origin string)

Source from the content-addressed store, hash-verified

124// The context is used for the initial connection establishment. It does not
125// affect subsequent interactions with the client.
126func DialWebsocket(ctx context.Context, endpoint, origin string) (*Client, error) {
127 if origin == "" {
128 var err error
129 if origin, err = os.Hostname(); err != nil {
130 return nil, err
131 }
132 if strings.HasPrefix(endpoint, "wss") {
133 origin = "https://" + strings.ToLower(origin)
134 } else {
135 origin = "http://" + strings.ToLower(origin)
136 }
137 }
138 config, err := websocket.NewConfig(endpoint, origin)
139 if err != nil {
140 return nil, err
141 }
142
143 return newClient(ctx, func(ctx context.Context) (net.Conn, error) {
144 return wsDialContext(ctx, config)
145 })
146}
147
148func wsDialContext(ctx context.Context, config *websocket.Config) (*websocket.Conn, error) {
149 var conn net.Conn

Callers 1

DialContextFunction · 0.85

Calls 2

newClientFunction · 0.85
wsDialContextFunction · 0.85

Tested by

no test coverage detected