Inter-Role Communication

Posted: July 26, 2013 in Live in a Cloudy World, Windows Azure

Now as we have known the Windows Azure Cloud Services whether a webrole, a workerrole and how to communicate between them using Queue storage.

 

If you are going to develop an application on Windows Azure and you want to make the required connection between multiple roles first thing you have to define is your endpoints. For the role you are going to allow the connection to reach you will have to create its endpoint and consider it as input endpoint. To do so you will have to go to the role you created in the cloud project and double click on it to go to its properties. To the Endpoint tab and create a new Endpoint. Choose its type to “Input” and enter the value of the port. The following figure shows you how:

Enter the following 2 libraries:

using
System.Net.Sockets;

using
System.IO;

 

After that in your application just create a new TcpListener to receive the incoming request. Once the Tcp listener accept the incoming traffic from the specified endpoint previously created. To do so, there is an example code.

TcpListener
listener
=
new
TcpListener(RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[“EndpointName”].IPEndpoint);


listener.AcceptTcpClient();

 

After that you can read or write directly from the stream whether a stream reader or a stream writer. Now you have a Worker Role that accepts the communication from the endpoint whether it was from another role or any other application.

Here is a nice video clarifying more how to deal with the inter role communication.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s