EntityOrientedCommunication 1.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package EntityOrientedCommunication --version 1.1.3
NuGet\Install-Package EntityOrientedCommunication -Version 1.1.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EntityOrientedCommunication" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityOrientedCommunication --version 1.1.3
#r "nuget: EntityOrientedCommunication, 1.1.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EntityOrientedCommunication as a Cake Addin
#addin nuget:?package=EntityOrientedCommunication&version=1.1.3

// Install EntityOrientedCommunication as a Cake Tool
#tool nuget:?package=EntityOrientedCommunication&version=1.1.3

EntityOrientedCommunication

A C/S framework library which allows object2object communication based on TCP/IP written in C#.

Highlights

⭐ Easy to use ⭐ Lightweight ⭐ Flexible

Table of Contents

  1. Quick Start </br> 1.1 Server Console </br> 1.2 Client Console </br> 1.3 Excution Results </br>
  2. Intoduction </br>
  3. EOC Server </br>
  4. Entity </br>
  5. Client Postoffice </br>
  6. Client Mailbox </br>

<a name="QuickStart"></a>

1.Quick Start

Assume there are 2 objects A and B on different computers, now they need to send messages to each other.

  • It is able to use the libraray without downloading source code of which. Since the compiled library was published on nuget.org, we might use EntityOrientedCommunication library by installing the nuget packge through some facilities. e.g. PackageManager, etc.
    PM> Install-Package EntityOrientedCommunication -Source nuget.org
    

<a name="section1_1"></a>

1.1 Server Console

Firstly we need to create a server console application, the code of the Mail(string[]) is shown as follwing.

using System.Threading;
using EntityOrientedCommunication;
using EntityOrientedCommunication.Server;

namespace ServerDemo
{
    class Program
    {
        public static void Main(string[] args)
        {
        	// create a server named 'EOCServerDemo' at 127.0.0.1:1350
            var server = new Server("EOCServerDemo", "127.0.0.1", 1350);

            // create 2 users without password
            server.MailCenter.Update(new User() { Name = "Mary" });
            server.MailCenter.Update(new User() { Name = "Tom" });

            // run the server
            server.Run();

            while (true) Thread.Sleep(1);
        }
    }
}

Now the code of server program is done, we will get a server execution file after the code is compiled, execute the file to run the server.


<a name="section1_2"></a>

1.2 Client Console

Similiar to section 1.1, we need to create a client console application first. Then declare a class that implements the interface named IEntity in the application. In order to make this quick start conciser, we suppose the objects A and B are of same type named SignalStation.

using EntityOrientedCommunication;
using System;


namespace ClientDemo
{
    class SignalStation : IEntity
    {
        public string EntityName { get; }

        public SignalStation(string name)
        {
            this.EntityName = name;
        }

        public LetterContent Pickup(ILetter letter)  // handle the incoming message
        {
            Console.WriteLine($"{this.EntityName} received message from {letter.Sender}: {letter.Title}, {letter.Content}");
            return null;
        }
    }
}

Hitherto we have a class named SignalStation in the client console assembly, then code the Mail(string[]) function of client program.

using EntityOrientedCommunication.Client;
using System;

namespace ClientDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            /****** A@Mary START ******/  // Code block 1
            var postoffice1 = new ClientPostOffice();
            var agent1 = postoffice1.Connect("127.0.0.1", 1350);  // create a client agent with specified server IP and port
            agent1.Login("Mary", "", 10000);  // login with account 'Mary' without password
            var objA = new SignalStation("A");  // create a 'SignalStation' instance named 'A'
            var boxA = postoffice1.Register(objA);  // register a mailbox for 'A' to grant it to communicate with other entities
            /****** A@Mary END ******/

            /****** B@Tom START ******/  // Code block 2
            var postoffice2 = new ClientPostOffice();
            var agent2 = postoffice2.Connect("127.0.0.1", 1350);
            agent2.Login("Tom", "", 10000);
            var objB = new SignalStation("B");
            var boxB = postoffice2.Register(objB);
            /****** B@Tom END ******/

            // 'B' send a message to 'A'
            boxB.Post("A@Mary", "hello A!", "put the content here.");

            Console.ReadKey();
        }
    }
}

Certainly the code block 1 and 2 could be put at two diffrenct applications, and the two applications could run on different computers. Just make the agents point to same server if you want to connect the objects.


<a name="section1_3"></a>

1.3 Execution Results

The execution result of the client console seems like following.

Client console execution result

And similiar the server console is.

Server console execution result

Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.5 481 5/25/2020
1.1.4 464 5/20/2020
1.1.3 438 5/16/2020
1.1.2 427 5/14/2020
1.1.1 430 5/13/2020
1.1.0 415 5/13/2020
1.0.7 432 5/12/2020
1.0.6 447 5/8/2020
1.0.5 450 5/8/2020
1.0.4 429 5/7/2020
1.0.3 429 5/7/2020
1.0.1 437 5/6/2020
1.0.0 423 5/6/2020

Replace Newtonsoft.Json with System.Runtime.Serialization.Formatters.Binary. Users of this lib need to update both client and server .dll reference to make the applications work fine.