About packages via Reflection x Manually

Asked

Viewed 47 times

0

Well, the title may not have been very explanatory, but I hope to improve on the content of the topic.

I made a library in C# in which to date, manually writes packages, as in the example below:

//Escrevendo o pacote
SocketPacket Packet = new SocketPacket(PacketID.AccountID);
Packet.WriteString(Username);
Packet.WriteString(Password);

Client.Socket.Send(Packet);

//Lendo o pacote
switch(Packet.ID)
{
 .....
    case PacketID.AccountID:
         string Username = Packet.ReadString();
         string Password = Packet.ReadString();
 .....
}

It’s working fine, but as you can see, I always have to read and write the packages manually. However, I had an idea, in which the data of the package would be stored in a class, which would implement an interface, forcing it to have an execution method, as in the example below:

public class AccountPacket : IPacket
{
   public string Username { get; set; }
   public string Password { get; set; }

   public void Execute()
   {
      ....
   }
}

Testing on the local server, there is no drastic change of speed, but I have no way to test on some remote server, in order to check the speed of both methods.

For those who have already supported my mania for extensive explanations, the question would be which of the methods would be recommended for a server, in the case only for real-time games (in which packages are always sent non-stop to several clients). In the first case, it would be something done manually, already in the second, as I said, I’m using Reflection, next to the method Getproperty.

I thank anyone who can answer.

  • Despite the long explanation I think that some fundamental things are missing to understand what you are doing, what you want and if you are having any problems. What I can already tell you is that if you need performance don’t use Reflection. This is a very slow feature useful in cases where you need an integration where there is no other way or need to create an abstraction to gain programming productivity. Performance is achieved by giving up comfort. It certainly has some reasonably comfortable way of doing the same without reflection. Probably not on the same level.

  • First of all, thank you for your reply. I had no problems creating the method which serializes the data of a certain class and sends via socket, but so far I could only test by local means. I already use this method to serialize and deserialziar data of a certain table and save in a model, which works very well, but as it would be speaking of a socket used for games (in the case in real time, with a certain amount of bundles lined up).

  • Testing by local means is ideal, because then the infrastructure will degrade more. It would be interesting to make aProfiling of the application to find out the exact points where it is having higher cost.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.