Open LacusCon opened 4 months ago
can you share a reproduction repo / zip
Without using builder.Serializer = protobuf.NewSerializer(), push string is successful. When protobuf is enabled, push string or proto will fail. [fail code1] func (s PushAbout) PushTest(ctx context.Context) (proto.CommonResp, error) { resp := &proto.CommonResp{Err: proto.ErrCodeOK} session := s.app.GetSessionFromCtx(ctx) = session.Push("push.lobby.game_state", resp) return resp, nil } [log1] level=debug msg="Type=Push, ID=1, UID=, Route=push.lobby.game_state, Data=" source=pitaya [client not receive]
[fail code2]
func (s PushAbout) PushTest(ctx context.Context) (proto.CommonResp, error) {
resp := &proto.CommonResp{Err: proto.ErrCodeOK}
session := s.app.GetSessionFromCtx(ctx)
= session.Push("push.lobby.game_state", *resp)
return resp, nil
}
[log2]
level=debug msg="Type=Push, ID=1, UID=, Route=push.lobby.game_state, Data={state:{NoUnkeyedLiterals:{} DoNotCompare:[] DoNotCopy:[] atomicMessageInfo:
I found the cause of this problem. It was caused by Marshal(m Message) ([]byte, error). If the proto message uses the default value, there will be a problem. enum ErrCode { OK = 0; ERR = 1; } message CommonResp { ErrCode err = 1; } [code]: resp1 := &proto.CommonResp{Err: proto.ErrCode_OK} session.Push("test.x.y", resp1) [failed]:
[code]: resp2 := &proto.CommonResp{Err: proto.ErrCode_ERR} session.Push("test.x.y", resp2) [success]:
I had a similar issue with SendPushToUsers
, an empty proto message doesn't throw any exceptions nor calls the client listener, to fix this, I added an arbitrary attribute called status
to the proto and worked
// base.proto
syntax = "proto3";
package protos;
message MyResponse {
+ bool status = 1;
}
// usage.go
pushResponse := &protos.MyResponse{
+ Status: true,
}
pitayaInstance.SendPushToUsers("myRoute", pushResponse, myUsers, "myType")
We went through this recently in one of our projects. The problem is in the libpitaya c code: https://github.com/topfreegames/libpitaya/blob/master/src/pc_trans.c#L244
Zero-length messages are ignored on pushes, so it never reaches the C# code where messages would be unmarshalled / callbacks invoked.
When I use Unity SDK, I can use request and response messages, but I can't receive messages from the server through Session Push. I have already registered through OnRoute