Zero-configuration socket TCP Message Communication Service container EC

Source: Internet
Author: User

The full name of EC is elastic communication. It is a Socket network communication service container Based on C # and supports windows. NET and mono. Through the EC container, developers can deploy logical applications to a network communication service without understanding the Socket network communication knowledge or any configuration. The goal of EC is to make it as simple as writing an Asp.net application when writing traditional Socket network communication services, you only need to define the message and controller methods to implement a network-based socket communication application service program.

The following uses a helloword routine to describe the simple flexibility of EC in this regard. To write services through EC, you only need to analyze the problem from the business. To analyze the scenario, you must first initiate a hello request server, then the service responds according to the content.

Define behavior message
    [MessageID(0x1)]    [ProtoContract]    public class Hello    {        [ProtoMember(1)]        public string Name { get; set; }    }
Define behavior Methods
    [Controller]    public class Program    {        static void Main(string[] args)        {            ECServer.Open();            System.Threading.Thread.Sleep(-1);        }        public string HelloWord(ISession session,Hello e)        {            return string.Format("hello {0} [say time:{1}]", e.Name, DateTime.Now);        }    }
Request Initiation
string result=mClient.Send<string>(new Hello { Name="henry" });

The above is the complete implementation of EC helloword. In the whole implementation process, there is no need to care about network issues or how messages and controllers are taken over by EC, you only need to execute ecserver. the open () method service can be started. The ease of use is described in the preceding example. The following describes the overall structure of EC.

EC Structure

The application at the top layer of EC is created and started by ecserver. open (). In the application layer, it mainly includes the protocol analyzer packetanalyzer, messagecenter in the message processing center, user session, and appmodel in the application module.

  • Packetanalyzer
    Protocol analyzer is mainly used to define the conversion of network stream data and message objects. To facilitate the application of EC's built-in protobuf protocol analyzer, we will introduce the protocol specifications later.
  • Messagecenter
    Message Processing Center, mainly used for message controller distribution and execution.
Protocol

To be ready for use, EC provides a default analyzer for protobuf. developers can mount the EC container by planning and defining messages through protobuf. The protocol structure is as follows:

The Protocol definition is relatively simple. byte [4] refers to the message length. messages are divided into two major parts: Message Type (byte [2]) and message protobuf stream.

Filter

If you have used Asp.net MVC, you should be familiar with filter. Because EC also processes messages based on controller behavior, it also supports the filter function. filter allows you to easily and uniformly verify all requests, handle errors, track logs, and other functions.

    [Controller]    public class Controller    {        [SkipFilter(typeof(LoginFilter))]        [ThreadPool]        public User Regisetr(ISession session, User user)        {            user.CreateTime = DateTime.Now;            "Register invoke[Name:{0} Email:{1}]".Log4Debug(user.Name, user.EMail);            return user;        }        [AdminFilter]        public IList<User> Search(ISession session, Query query)        {            "Search invoke".Log4Debug();            List<User> users = new List<User>();            users.Add(new User());            users.Add(new User());            return users;        }    }
Session Status

The EC provides two session states for saving the global-based applicatoin and connected sessions.

            application.MethodProcess += (o, e) =>            {                //application                e.Application["Path"] = @"c:\";                //sexxion                e.Session["folder"] = "aaa";            };
Multi-platform support

EC supports both windows. NET and mono, and does not need to be adjusted or modified based on different platforms.

Download helloword

Http://ec.ikende.com/files/file/HelloWord20140903095823.rar

Download more routine code

 

Zero-configuration socket TCP Message Communication Service container EC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.