Creating a Custom Transport Service

Creating your own transport service is actually not that difficult, and you can concentrate all your efforts on how you transport the data from one end to another. The following code example shows which methods you need to implement when you are implementing transport service:

public class MyTransportService 
    : IXcoTransportService //this is the interface that needs to be implemented
    //this event should be raised when a new message has been received
    public event MessageReceivedDelegate OnMessageReceived;

    public string LocalAddress
        //return here the address of your local appspace. this should be the same 
        //address that other appspace instances can use to resolve a worker from 
        //this appspace
        get { } 

    public void Send(XcoMessage msg, string remoteAddress)
        //this method is called by the appspace when a message should be sent
        //to a remote space. "msg" contains all data that should be transported, 
        //"remoteAddress" is the address of the target space.
        //This method can work fully asynchronous - when a message has been
        //send successfully, it should call:
        //When the transfer of the message failed, it should call:

    public void Initialize(XcoAppSpaces.Contracts.Service.IXcoServiceRegistry serviceRegistry)
        //here you can access the service registry to get other services from the
        //running appspace instance. normally you can leave this method empty.

    public void Start()
        //this method is called at startup of the space, directly after "Initialize".
        //Here your transport service should be started, so that it is able to receive 
        //remote messages and hand them over to the space by raising the
        //OnMessageReceived event.

    public int StartPriority
        //defines in which order services of the xcoappspace are started. 
        //5 is the default for transport services.
        get { return 5; }

    public void Stop()
        //this method is called when the appspace is disposed and should stop 
        //the service (close all connections, release all resources, ...)

    public void Dispose()
        this.Stop(); //dispose is equal to stop, so you can just call stop here

You can see here how you to add your custom service to the space.
If you want more info on transport service implementation, you could take a look at the implementations of the other transport services.

Last edited May 26, 2012 at 1:56 PM by thomass, version 6


No comments yet.