Angel \”Java\” Lopez on Blog

June 11, 2010

Server and Client in Distributed AjSharp

Filed under: .NET, AjSharp, Distributed Computing, Open Source Projects — ajlopez @ 11:40 am

In my previous posts:

I wrote a brief description of what I want for distributed AjSharp (my open source interpreter), and few screenshots of running programs. Let examine and run a first concrete example.

As usual, you can launch the interactive interpreter with

AjSharp.Console

You can add a list of .ajs program files to read and run inmediatly:

AjSharp.Console program1.ajs program2.ajs

The idea in this first distributed example is to launch two instances of the interpreter, and then, start a server in the first one, and start a client of that server in the second one. After connection is done, the client can execute commands in the server.

First, the server code:

server = new RemotingHostServer(10000, "Server");
PrintLine("Server started");

The built-in class RemotingHostServer starts a remoting server connection. The first parameter is the TCP port, and the second parameter the logic name of the server.

Now, the code for the client node:

remote = new RemotingHostClient("localhost", 10000, "Server");
at remote PrintLine("New Node");
nodeid = System.Guid.NewGuid().ToString();
// evaluate a subroutine at server
at remote 
	sub(id)
	{
		for (k=1; k<=10; k++)
			PrintLine("Hello, server, from node " + id);
	}
	with (nodeid); // local parameter going to server
	
exit;

The object RemotingHostClient connects with a server. Its constructor takes three parameters: the machine name, the TCP port to use, and the logical name of the server. Using these parameters, it builds a remoting address, using a TCP channel.

Now, you have a connection with the server. The at command execute a command in a remote server. The syntax is:

at <server> <cmd>

Then

at remote PrintLine(“New Node”);

prints a message in the server console, not in the client. The other variant:

at <server> <functionorsub> with (<parameters>);

evaluates a function or subroutine at the server, passing the parameter list, evaluated in the client environment.

I prepared a packaged example, you can download from my Skydrive: AjSharpDistributed01.zip.

In a console, execute

StartServer.cmd

This command starts a new console, executing Server.ajs code.

To run a node

RunNode.cmd

This is the typical output at the server side:

As usual, you can get the complete source from:

http://code.google.com/p/ajcodekatas/source/browse/

under trunk/AjLanguage. More distributed examples are comming: execute a local source code file at the server, do something at server when a new node is running, distributed agents, etc…

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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

The Shocking Blue Green Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 57 other followers

%d bloggers like this: