Hi all!, please take a look on this, OTP.Net and EVO (Extended Visual Otp)

Ivan Carmenates García <>
Mon Sep 27 22:02:35 CEST 2010


Hi all, my name is Ivan I’m
from Cuba, I would like to promote Erlang in this country, I can say that we
are so small community here, What I know we are just 3 persons that knows
Erlang very much and it power, this is my second time I can join to this 
community,
I love Erlang, actually I am developing a new component to communicate 
clients
made in C# with Erlang servers, using the Otp.Net library of Vlad Dumitrescu
but I had wrote new layers to make so more easy the programming, I call my
component EVO (Extended Visual Otp)... a little example could be:





this.erlangServerInterface.Connect();





With that we are connecting
with the server in Erlang. The configuration is a visual one. There are no 
need
to write code for that.





And for requests you just have
to write:


this.erlangServerRequest.Request(“request description”, object message);





The object message could be anything
even an Otp.Erlang.Object object or c# object, for example:





this.erlangServerRequest.Request(“say hello!!!”, new object[] {new
Otp.Erlang.Atom("hello"), “Oh definitely I want to say hello to this
community”});





That’s the same to send a {hello, “Oh definitely I want to say hello to
this community”} message to Erlang.





We can do any kind of combination for example:


Person person1 = new Person(“Ivan”, “26”, “Cuba”)


This.erlangServerRequest.Request(“insert person data”, new object[] {“
‘insert_person’ “, person1} );





Is the same of {insert_person, person1}





The class Person of course must be marked as [serializable] attribute


But that is not all; to receive the replies the erlangServerRequest object
has an OnReceive method.





OnReceive(IServerReply _reply) {


If
(_reply.CSharpReply is Person) {


MessageBox.Show((_reply.CSharpReply as Person).Name );


}


}





There are 3 kinds of request in EVO. A normal request that waits for
request to be completed to return the control to the program, the async 
request
that starts a new thread for the request then you can make others request at
instant. And the sync request that waits for reply too.





this.erlangServerRequest.RequestAsync(“description”, object msg);





Or


IRequestInfo req = this.erlangServerRequest.Request(“description”, 
object
msg);


IServerReply reply = req.WaitForReply();





You can even abort the request once it was made. For example:





IRequestInfo req = this.erlangServerRequest.Request(“description”, 
object
msg);


req.AbortRequest ();





That means that you have the power to destroy the process in the server
that is resolving for your request. And of course ignore if there are any
possibility of be too late to abort request in server, then ignore the reply 
on
the client.





The magic here is that you can have in the same client many connections to
different servers and for each connection has many request handlers and for
each request handlers has many request made of sync or async way.





ErlangServerInterface interface1 = new ErlangServerInterface();


interface1.ServerAddress = “localhost”;


interface1.ServerPort = “5800”;


…


…


…





ErlangServerRequest requethandler1 = new ErlangServerRequest();


requesthandler1.ErlangServerInterface = interface1;





requesthandler1.Request(“say hi”, “ ‘ hi’ ”);


requesthandler1.Request(“say hello”, “ ‘ hello’ ”);








you can make many request through the same requesthandler1 and have no
confusion with the replies, because you can check that of this way:





OnReceive(IServerReply _reply) {


switch(_reply.Description)
{


case “say hi”:


// do what ever you want


break;


case “say hello”:


// do what ever you want here;


break;


}


}





In Erlang is so much easy and I had developed a super template to helps you
write even more easy code that you can write in Erlang this could be:





%% Request process code.


loopRequest(Args)->


receive


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%% USER FUNCTIONS TO MODIFY
                                                                        
%%


%%
                                                                             
                                                    
%%


%% Request: {Msg, Pid, RequestInfo}
                            
                        
                   
   %%


%%   Reply: {reply, Reply, RequestInfo}
                                                 
                     
  %%


%%
                                                                             
         
                     
                     %%


%% RequestInfo = {Description, Id, WasMade, Kind, RequestHandlerHash}
                  
%%


%%                                                                           
            
                     
                     %%


%% NOTE:
                                                                             
   
                     
               %%


%% - You can use send_to_all(Description, Msg) function to send a message to
all clients. %%


%% - Do not use 'loopRequest(Args)' calls in any clause.
                                                  
%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%








{hi, Pid, RequestInfo}->


io:format("message received: ~p~n", [Msg]),


Pid ! {reply, "yeah thanks for ask", RequestInfo};





{{update_char, CharName, X, Y}, Pid, RequestInfo}->


send_to_all(update_char, {CharName, X, Y});


%%R = appname_db_module:update_char(CharName, X, Y);





{get_chars, Pid, RequestInfo}->


Reply = appname_db_module:get_chars(),


Pid ! {reply, Reply, RequestInfo};





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%% TEMPLATE
                                                                         
%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





{Msg, Pid, RequestInfo}->


Reply =


%% Code Here.


Msg,





%% Replies to client.


Pid ! {reply, Reply, RequestInfo},





%% If you want to send a message to all clients.


send_to_all(description, Reply),





%% Debug message.


appname_debug_module:print(Args, reply, {Reply, Pid, RequestInfo})


end.








That and so much more functionalities can be made with this component that
I had called EVO. If there are any people interesting please can contact me 
in



More information about the erlang-questions mailing list