Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RpcServer serializer is wrong #296

Closed
anboo44 opened this issue Nov 11, 2023 · 4 comments
Closed

RpcServer serializer is wrong #296

anboo44 opened this issue Nov 11, 2023 · 4 comments

Comments

@anboo44
Copy link

anboo44 commented Nov 11, 2023

I make a small project to test RPC.

Screen Shot 2023-11-12 at 00 43 50 Screen Shot 2023-11-12 at 00 53 21 Screen Shot 2023-11-12 at 00 53 30

When i set JoinMsg.class is first at withMessageTypes, messages to my rpcServer are always serialized into JoinMsg.class
When i set CalcRpcMessage.class is first at withMessageTypes, messages to my rpcServer are always serialized into CalcRpcMessage.class

I don't understand why it is.
I want to class types don't care their order in withMessageTypes. RpcServer is based on class type that is declared with withHandler to serialize message.
Please give your advise

@eduard-vasinskyi
Copy link
Contributor

Hi, @anboo44
I have not been able to reproduce the problem. I have configured the RPC server the same way as you did, but the messages are serialized correctly.
Can you check that the message types (and their order) in RpcClient#withMessageTypes match the message types in RpcServer#withMessageTypes? If so, could you please create a test or demo project demonstrating the serializer issue?

I want to class types don't care their order in withMessageTypes.

To build compatible message serializers, the configuration of message types (the order of message types) must be the same on both the RPC client and the server.

@anboo44
Copy link
Author

anboo44 commented Nov 13, 2023

@eduard-vasinskyi I recognize that RpcClient#withMessageTypes and RpcServer#withMessageTypes are not matched. After i change them, it is OK. Thank you.

Assumed, RpcServer handles types: String, Integer, Boolean with 3 RpcClients
RpcClient_1 only uses String
RpcClient_2 only uses Integer
RpcClient_3 only uses Boolean
=> In order to work, RpcClient_1, RpcClient_2, RpcClient_3 must be the same with RpcServer. I think it isn't convenient.
Does the way have to change this in next versions ?
It will be great, if RpcClient only declares its types

@eduard-vasinskyi
Copy link
Contributor

@anboo44
The serializer must know which message type to decode. To do this, an index is assigned to each message type. The client serializer then encodes the index of the message type.

It is not possible to make a client that knows nothing about other message types.
Alternatively, you can create multiple RPC servers, each handling a different message type, and configure them to listen on different ports. This way, each client will connect to the desired server and will not need to know about the other message types.

@anboo44
Copy link
Author

anboo44 commented Nov 16, 2023

@eduard-vasinskyi I got it. Thank you so much

@anboo44 anboo44 closed this as completed Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants