Search code examples
c#xamarinnetwork-programming.net-corerpc

RPC in .NET Core and Xamarin


I am in the early stages of building an online collectible card game for mobile devices in C#. The game client itself is built with Xamarin, and will (eventually) run on both iOS and Android. The game server is a .NET Core console app, running on a Linux server.

However, I am having trouble deciding how to manage communications between the client and server. I am a complete beginner when it comes to networking; the main purpose of this project is to learn a bit about how to do it.

My plan is to use some form of RPC for communications between the two, so the client can simply call a method on the server and get a useful response back - something like:

CardCollection cards = Service.GetCards(playername);

Where GetCards(playername) is a method on the server made available using a service contract. My original intention was to use WCF with NetTcpBinding for this purpose, since it fits my needs perfectly. However, it turns out that isn't available in .NET Core. So instead I decided to use gRPC, which also does pretty much exactly what I need - except it turns out that isn't available for Xamarin.

So, my question is - is there a pre-existing library which I can use to manage the communication between my client and server that works in .Net Core and Xamarin, or am I going to need to create something of my own? If I need to write something myself, is there any useful documentation/guidance around on how best to do this in .NET? I have found tutorials for building a basic TCP server, but that's pretty much it. I have no idea how to scale that up to my needs.

Pretty much all the information I have found so far has been about creating RESTful web services, which is a bit different to what I need. I don't actually need many of the features of a REST API, and I would prefer to communicate directly over TCP rather than HTTP, to ensure maximum performance - although I could be convinced otherwise if necessary. The server also needs to be able to handle many requests at once concurrently.


Solution

  • Well, I couldn't find any documentation on how to implement RPC between a .NET Core Server and a Xamarin client from scratch, or any information on any other way to do it.

    However, after much searching, I came across Thrift, which does (apparently) support both Xamarin and .NET Core, and pretty much perfectly matches the way I want to do things. I am having some difficulties getting it working, but that belongs in a question of its own, I think.