@@ -12,6 +12,8 @@ go get github.com/hyperf/roc
1212
1313[ roc-skeleton] ( https://github.com/limingxinleo/roc-skeleton )
1414
15+ ### For Server
16+
1517- action/foo_save_action.go
1618
1719``` go
@@ -121,6 +123,84 @@ func main() {
121123
122124```
123125
126+ ### For Client
127+
128+ ``` go
129+ package main
130+
131+ import (
132+ " fmt"
133+ cli " github.com/hyperf/roc/client"
134+ " github.com/hyperf/roc/formatter"
135+ " time"
136+ )
137+
138+ type FooSaveInput struct {
139+ Name string ` json:"name"`
140+ Gender int ` json:"gender"`
141+ }
142+
143+ type FooSaveRequest struct {
144+ ID int
145+ Input *FooSaveInput
146+ }
147+
148+ type FooSaveResult struct {
149+ IsSuccess bool ` json:"is_success"`
150+ }
151+
152+ type LocalAddr struct {
153+ }
154+
155+ func (l LocalAddr ) Network () string {
156+ return " tcp"
157+ }
158+
159+ func (l LocalAddr ) String () string {
160+ return " 127.0.0.1:9501"
161+ }
162+
163+ func (f *FooSaveRequest ) MarshalJSON () ([]byte , error ) {
164+ return formatter.FormatRequestToByte (f)
165+ }
166+
167+ var client *cli.Client
168+
169+ func init () {
170+ var err error
171+ client, err = cli.NewAddrClient (&LocalAddr{})
172+ if err != nil {
173+ fmt.Println (err)
174+ }
175+ }
176+ func main () {
177+ req := FooSaveRequest{ID: 1 , Input: &FooSaveInput{Name: " limx" , Gender: 1 }}
178+ id , _ := client.SendRequest (" /foo/save" , &req)
179+
180+ ret := &formatter.JsonRPCResponse [FooSaveResult, any]{}
181+ err := client.Recv (id, ret, cli.NewDefaultRecvOption ())
182+ if err != nil {
183+ fmt.Println (err)
184+ }
185+
186+ fmt.Println (ret.Result .IsSuccess )
187+
188+ for {
189+ req = FooSaveRequest{ID: 1 , Input: &FooSaveInput{Name: " error" , Gender: 1 }}
190+ id, _ = client.SendRequest (" /foo/save" , &req)
191+
192+ ret = &formatter.JsonRPCResponse [FooSaveResult, any]{}
193+ err = client.Recv (id, ret, cli.NewDefaultRecvOption ())
194+ if err != nil {
195+ fmt.Println (err)
196+ }
197+
198+ time.Sleep (time.Second )
199+ }
200+ }
201+
202+ ```
203+
124204## Related Repositories
125205
126206- [ multiplex] ( https://github.com/hyperf/multiplex ) Channel driven multiplexing connection for PHP.
0 commit comments