diff --git a/client/client.go b/client/client.go index fede17a..9e2ef53 100644 --- a/client/client.go +++ b/client/client.go @@ -267,8 +267,11 @@ func (c *client) rpcWriter(stopChan <-chan struct{}, writerDone chan<- error) { continue } } - - err = c.ch.GetCodec().Write(c.conn, cs.Method, cs.Args, cs.ID) + var requestID interface{} + if 0 < cs.ID { + requestID = cs.ID + } + err = c.ch.GetCodec().Write(c.conn, cs.Method, cs.Args, requestID) if !cs.hasResponse { cs.Error = err cs.Done() @@ -296,7 +299,8 @@ func (c *client) rpcReader(readerDone chan<- error) { crn, err := c.ch.GetCodec().NewResponseOrNotify(c.conn) if nil != err { err = fmt.Errorf("Client: Cannot decode response or notify: [%s]", err) - return + logging.Logger().Error(err.Error()) + continue } if crn.IsResponse() { @@ -305,7 +309,8 @@ func (c *client) rpcReader(readerDone chan<- error) { err = c.notifyHandle(crn.GetNotify()) } if nil != err { - return + logging.Logger().Error(err.Error()) + continue } } diff --git a/protocol/json/client.go b/protocol/json/client.go index 0d05df3..28c3aab 100644 --- a/protocol/json/client.go +++ b/protocol/json/client.go @@ -47,7 +47,7 @@ type clientNotify struct { Method string `json:"method"` // Object to pass as request parameter to the method. - Params *json.RawMessage `json:"params"` + Params *json.RawMessage `json:"params,omitempty"` } // ---------------------------------------------------------------------------- diff --git a/protocol/json/client_response.go b/protocol/json/client_response.go index 969a120..165bd59 100644 --- a/protocol/json/client_response.go +++ b/protocol/json/client_response.go @@ -21,7 +21,7 @@ func newClientCodecResponse(raw json.RawMessage) (protocol.ClientCodecResponse, releaseClientCodecResponse(ccr) return nil, err } - if nil == ccr.response.ID { + if 0 == ccr.response.ID { releaseClientCodecResponse(ccr) return nil, fmt.Errorf("This is not Response") } @@ -81,7 +81,7 @@ func releaseClientCodecResponse(ccr *ClientCodecResponse) { ccr.response.Version = "" ccr.response.Result = nil ccr.response.Error = nil - ccr.response.ID = nil + ccr.response.ID = 0 clientCodecResponsePool.Put(ccr) } diff --git a/protocol/json/server.go b/protocol/json/server.go index 6f8f53b..d4719a1 100644 --- a/protocol/json/server.go +++ b/protocol/json/server.go @@ -24,12 +24,12 @@ type serverRequest struct { Method string `json:"method"` // A Structured value to pass as arguments to the method. - Params *json.RawMessage `json:"params"` + Params *json.RawMessage `json:"params,omitempty"` // The request id. MUST be a string, number or null. // Our implementation will not do type checking for id. // It will be copied as it is. - ID *json.RawMessage `json:"id"` + ID *json.RawMessage `json:"id,omitempty"` } // serverResponse represents a JSON-RPC response returned by the server. @@ -48,7 +48,7 @@ type serverResponse struct { Error *Error `json:"error,omitempty"` // This must be the same id as the request it is responding to. - ID *json.RawMessage `json:"id"` + ID *json.RawMessage `json:"id,omitempty"` } // ----------------------------------------------------------------------------