Git Product home page Git Product logo

feather2's Introduction

InvertedTomato.Feather2

Feather2 is extremely fast and lightweight network messaging system. It's kinda like WCF, without the nonsense and with scolding fast speeds. It's great for applications communicating over a network when speed, efficiency or the one-way nature of traditional web APIs isn't a great fit.

Feather2 is the replacement of Feather1. Feather1 was great, though it's interface was cumbersome in areas, it lacked flexibility and UDP support and it was limited to .NET Framework. Feather2 addresses all of those issues.

TLDR, how do I make it go?

TCP Server

static void Main(string[] args) {
	using (var server = new FeatherTcpServer<GenericMessage>()) {
		// Watch for when clients connect
		server.OnClientConnected += (endPoint) => {
			Console.WriteLine($"{endPoint} connected.");
		};

		// Watch for when clients disconnect
		server.OnClientDisconnected += (endPoint, reason) => {
			Console.WriteLine($"{endPoint} disconnected.");
		};

		// Watch for messages to arrive
		server.OnMessageReceived += (endPoint, message) => {
			// Read parameters in the same order they were written
			var name = message.ReadString();
			var body = message.ReadString();
			Console.WriteLine($"{name}> {body}");

			// Forward message on to all clients (including the sender, for confirmation)
			foreach (var remoteEndPoint in server.RemoteEndPoints) {
				server.SendTo(remoteEndPoint, message);
			}
		};

		// Listen for inbound connections
		server.Listen(12345);

		// Wait for key press to shutdown
		Console.WriteLine("Server now listening for connections on port 12345. Press any key to halt.");
		Console.ReadKey(true);
	}
}

TCP Client

static void Main(string[] args) {
    Console.WriteLine("What is your name?");
    var myName = Console.ReadLine();

    using (var client = new FeatherTcpClient<GenericMessage>()) {
        // Watch for messages to arrive
        client.OnMessageReceived += (message) => {
            // Read parameters in the same order they were written
            var name = message.ReadString();
            var body = message.ReadString();
            Console.WriteLine($"{name}> {body}");
        };

        // Watch for disconnetion
        client.OnDisconnected += (reason) => {
            Console.WriteLine($"Disconnected because '{reason}'.");
        };

        // Connect to server
        client.Connect("127.0.0.1", 12345);

        // Loop sending messages
        Console.WriteLine("Connected. Type message to send.");
        while (true) {
            var body = Console.ReadLine();
            if (body == string.Empty) {
                break;
            }

            // Create message
            var message = new GenericMessage();
            message.WriteString(myName);
            message.WriteString(body);

            // Send message to broadcast address
            client.Send(message);
        }
    }
}

UDP Peer

static void Main(string[] args) {
    Console.WriteLine("What is your name?");
    var myName = Console.ReadLine();
            
    using (var peer = new FeatherUdpPeer<GenericMessage>()) {
        // Watch for messages to arrive
        peer.OnMessageReceived += (endpoint, message) => {
            var name = message.ReadString();
            var body = message.ReadString();
            Console.WriteLine($"{name}> {body}");
        };

        // Bind socket to receive messages
        peer.Bind(12345);

        // Loop sending messages
        Console.WriteLine("Type message to send.");
        while (true) {
            var body = Console.ReadLine();
            if (body == string.Empty) {
                break;
            }

            // Create message
            var message = new GenericMessage();
            message.WriteString(myName);
            message.WriteString(body);

            // Broadcast message on the local network (similarly, we could send to a specific address on the internet instead)
            peer.SendTo(new IPEndPoint(IPAddress.Broadcast, 12345), message);
        }
    }
}

Where do I get it from?

You can find it on NuGet.

feather2's People

Contributors

invertedtomato avatar

Stargazers

 avatar  avatar Serge Eric Hotegni avatar Bradley S. avatar Will Sahatdjian avatar

Watchers

 avatar James Cloos avatar D Bullock avatar Bradley S. avatar

feather2's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.