Skip to content

CodeElements/NetworkCallTransmission

Repository files navigation

NetworkCallTransmission

This library is designed to make calls over a network interface (e. g. TCP) as easy as possible while still giving the developer full control over the transmission process (in contrast to WCF). Two important functions are provided: the CallTransmission which allows you to call methods over the network and awaiting them. The event manager which allows you to subscribe to events from the remote side and manage these subscriptions (give events specific permissions on the server side, filter unwished events on the client side, e. g.).

Goals

The most important aspect is performance, especially for the server classes. Everything is cached, reflection is not used after initialisation, one instance for all clients, etc. This library will be used in a production environment which may have to serve more than 10,000 clients. Second, everything should be as easy to implement as possible. Surely the most performant way to call methods over the network would be to give methods an enum id and completly work without an interface. The problem here is that it is much harder to implement simple methods and that is a huge problem, especially for a one-man project.

Serialization

I spend a full day comparing different serialization methods to find the best. The candidates were NetSerializer, ProtoBuf and ZeroFormatter. The most important aspect again is performance, then comes usability and data size. Both, NetSerializer and ZeroFormatter are very fast, ProtoBuf was by far the slowest. I couldn't really determine if NetSerializer or ZeroFormatter were faster, some tests saw ZeroFormatter as the fastest algorithm but in my tests NetSerializer was a little bit faster in some scenarios. The next point actually takes the decision: The usability of ZeroFormatter is by far better than NetSerializer. First of all, because the serialization/deserialization is done by this library, NetSerializer has no internal way to mark abstract classes so that I must have implemented that (in earlier commits where NetSerializer was implemented, you can see that I solved that using the AdditionalTypesAttribute, but that was far from optimal). Another point is the backwards compatibility. That wasn't actually something I really cared about but NetSerializer doesn't allow any changes regarding the object structure. ZeroFormatter allows additions without the other side having to know them. In terms of size, ZeroFormatter is almost the worst one of all tested serializers. But that isn't that important because a simple compression algorithm should anyways compress the data before sending and we are talking about a few bytes here for simple types and a TCP package is a TCP package, if it contains 10 bytes or 1000 bytes, talking about small objects.

Async

I'm a huge fan of the async/await stuff. Especially when it comes to I/O, it is a lot better than blocking a thread who technically doesn't do anything else than waiting. All methods which are required to do network operations or other async stuff are tasks by design so you don't loose threads on waiting. If you still prefer synchronous methods, you can just always return Task.CompletedTask.

About

A very fast network transmission library for method calls and events.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published