AboutBlogContact
Backend EngineeringSeptember 28, 2002 2 min read 117Updated: May 18, 2026

Distributed .NET: Remoting with TCP Channels (2002)

AunimedaAunimeda
📋 Table of Contents

Distributed .NET: Remoting with TCP Channels

With the release of the .NET Framework 1.0, Microsoft has given us a powerful alternative to DCOM: .NET Remoting. While everyone is talking about Web Services (SOAP/HTTP), the real performance junkies know that for internal distributed systems, binary serialization over a raw TCP channel is where it's at.

Defining the Remote Object

The object you want to share must inherit from MarshalByRefObject. This tells the .NET runtime that the object stays on the server, and the client gets a "transparent proxy."

public class RemoteCalculator : MarshalByRefObject {
    public int Add(int a, int b) {
        Console.WriteLine("Calculation requested: {0} + {1}", a, b);
        return a + b;
    }
}

Setting up the Server

We need to register a TcpChannel and then register our service. We'll use WellKnownObjectMode.Singleton so all clients talk to the same instance.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Server {
    public static void Main() {
        TcpChannel channel = new TcpChannel(8080);
        ChannelServices.RegisterChannel(channel);
        
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(RemoteCalculator),
            "CalculatorService",
            WellKnownObjectMode.Singleton
        );
        
        Console.WriteLine("Server started. Press Enter to exit...");
        Console.ReadLine();
    }
}

The Client Side

The client just needs to connect to the URL and cast the resulting proxy.

TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel);

RemoteCalculator calc = (RemoteCalculator)Activator.GetObject(
    typeof(RemoteCalculator),
    "tcp://localhost:8080/CalculatorService"
);

int result = calc.Add(10, 20);
Console.WriteLine("Result: " + result);

Why Binary over TCP?

SOAP/HTTP is great for interoperability, but parsing XML is slow and the HTTP protocol adds significant header overhead. By using the BinaryFormatter and raw TCP, we reduce the payload size by up to 70% and eliminate the latency of a web server like IIS. If you're building a high-frequency trading platform or a heavy-duty back-office system on Windows, Remoting is your best friend.

Just be careful with the firewall-port 8080 isn't always open!


Aunimeda builds production-grade backend systems - APIs, microservices, real-time applications, and system integrations.

Contact us for backend engineering services. See also: Custom Software Development, Web Development

Read Also

WebRTC: Scaling P2P Mesh Networking for Real-time Video (2019)aunimeda
Backend Engineering

WebRTC: Scaling P2P Mesh Networking for Real-time Video (2019)

Is it possible to build a video chat app without an expensive media server? In 2019, we're exploring the limits of WebRTC mesh networking.

eBPF: In-Kernel Programmability for Networking and Security (2018)aunimeda
Backend Engineering

eBPF: In-Kernel Programmability for Networking and Security (2018)

Linux 4.x is changing the game with eBPF. Why write kernel modules when you can run safe, verified bytecode directly in the kernel?

Node.js 0.2: Scaling to 10k Connections on One Threadaunimeda
Backend Engineering

Node.js 0.2: Scaling to 10k Connections on One Thread

Ryan Dahl's Node.js project has hit version 0.2. It's JavaScript on the server, but the real magic is the non-blocking I/O model.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles