When the server application calls
} the server is switching from the WebSocket protocol to the JSON-RPC protocol. The browser continues to use the WebSocket protocol. The connection is closed because one of the peers errors out reading a protocol that it does not expect.
The problem does not happen with the Go client application because this application also switches from the WebSocket protocol to the JSON-RPC protocol.
It is not possible to access the underlying network connection from a browser application.
It is possible to use the net/rpc package with Codec written to use the WebSocket protocol. Another option is to write an adaptor to convert the message based WebSocket API to the stream expected by the net/rpc/jsonrpc server.