Answer the question
In order to leave comments, you need to log in
How to organize message processing on the server?
I am developing a game like HearthStone in c#. Server on TCPClient. At this stage, I'm trying to organize the processing of messages. The Message class encoded in json goes between the client and the server
public class Message
{
public MessageContent Content { get; set; }
public Encoding Encoding { get; set; }
public int BufferLengthSize { get; set; }
public Type Type { get; set; }
}
public class AttackMessage : MessageContent
{
public int AtackCartId { get; set; }
public int AttackedCartId { get; set; }
}
container.RegisterType<IController, AttackMessageController>(nameof(AttackMessage));
var controller = container.Resolve<IController>(response.Type.Name);
var response = controller.GetResponse(response.Content)
Answer the question
In order to leave comments, you need to log in
If you use a separate container for controllers, then this solution is possible, but in fact the container can be replaced with a regular one Dictionary<Type, IController>
.
If you register your controllers in a shared container, it looks weird.
And in general, the structure of the Message class is questionable. Why Encoding and BufferLengthSize? Why is Type of type System.Type and not System.String?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question