Erlang gen server and c++ client

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang gen server and c++ client

benefit
This post has NOT been accepted by the mailing list yet.
Hello.
Please help me.
I need to make a erlang gen_server which works with an erlang port.
An c++ application must connect to erlang port and send a string. Server should return the same string to the application.

I have troubles working with erlang.
I found an example code :

connect(Message) ->
    Cmd = "./myqtwindowapp \n",
    Port = open_port({spawn,Cmd}, [stream,use_stdio,exit_status]),
    Payload = string:concat(Message, "\n"),
    erlang:port_command(Port, Payload),
    receive
        {Port, {data, Data}} ->
            ?DBG("Received data: ~p~n", [Data]),
        Other ->
            io:format("Unexpected data: ~p~n", [Other])
    after 15000 ->
            ?DBG("Received nothing~n", [])
    end.
 

But i dont know how to run this code. I tried erl -run serv start but recieved error in do_boot. And how to include this code into a small module? Even i recieved error in dbg macros.

Please help me. Suggest me how to finalize. I am newbie here, please suggest me how to run this code or other.
Any help is appreciated.
Reply | Threaded
Open this post in threaded view
|

Erlang gen server and c++ client

Rapsey-2
Your description is very confusing.
Erlang runs a c++ app and communicates with it over a port?
Your problem is how to actually launch Erlang that executes your code?
erl -eval "module:function()"


Sergej

On Wed, Jun 13, 2012 at 11:51 AM, benefit <dangodiac> wrote:

> Hello.
> Please help me.
> I need to make a erlang gen_server which works with an erlang port.
> An c++ application must connect to erlang port and send a string. Server
> should return the same string to the application.
>
> I have troubles working with erlang.
> I found an example code :
>
> connect(Message) ->
>    Cmd = "./myqtwindowapp \n",
>    Port = open_port({spawn,Cmd}, [stream,use_stdio,exit_status]),
>    Payload = string:concat(Message, "\n"),
>    erlang:port_command(Port, Payload),
>    receive
>        {Port, {data, Data}} ->
>            ?DBG("Received data: ~p~n", [Data]),
>        Other ->
>            io:format("Unexpected data: ~p~n", [Other])
>    after 15000 ->
>            ?DBG("Received nothing~n", [])
>    end.
>
>
> But i dont know how to run this code. I tried erl -run serv start but
> recieved error in do_boot. And how to include this code into a small
> module?
> Even i recieved error in dbg macros.
>
> Please help me. Suggest me how to finalize. I am newbie here, please
> suggest
> me how to run this code or other.
> Any help is appreciated.
>
> --
> View this message in context:
> http://erlang.2086793.n4.nabble.com/Erlang-gen-server-and-c-client-tp4655136.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120613/2227b074/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Erlang gen server and c++ client

Bengt Kleberg-4
In reply to this post by benefit
Greetings,

To run Erlang code you need to put it into a module (file) and compile
it. See http://learnyousomeerlang.com or another similar website.


bengt

On Wed, 2012-06-13 at 11:51 +0200, benefit wrote:

> Hello.
> Please help me.
> I need to make a erlang gen_server which works with an erlang port.
> An c++ application must connect to erlang port and send a string. Server
> should return the same string to the application.
>
> I have troubles working with erlang.
> I found an example code :
>
> connect(Message) ->
>     Cmd = "./myqtwindowapp \n",
>     Port = open_port({spawn,Cmd}, [stream,use_stdio,exit_status]),
>     Payload = string:concat(Message, "\n"),
>     erlang:port_command(Port, Payload),
>     receive
>         {Port, {data, Data}} ->
>             ?DBG("Received data: ~p~n", [Data]),
>         Other ->
>             io:format("Unexpected data: ~p~n", [Other])
>     after 15000 ->
>             ?DBG("Received nothing~n", [])
>     end.
>  
>
> But i dont know how to run this code. I tried erl -run serv start but
> recieved error in do_boot. And how to include this code into a small module?
> Even i recieved error in dbg macros.
>
> Please help me. Suggest me how to finalize. I am newbie here, please suggest
> me how to run this code or other.
> Any help is appreciated.
>
> --
> View this message in context: http://erlang.2086793.n4.nabble.com/Erlang-gen-server-and-c-client-tp4655136.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions




Reply | Threaded
Open this post in threaded view
|

Erlang gen server and c++ client

Serge Aleynikov-4
In reply to this post by benefit
See this tutorial for help:

http://trapexit.org/How_to_use_ei_to_marshal_binary_terms_in_port_programs

On 6/13/2012 5:51 AM, benefit wrote:

> Hello.
> Please help me.
> I need to make a erlang gen_server which works with an erlang port.
> An c++ application must connect to erlang port and send a string. Server
> should return the same string to the application.
>
> I have troubles working with erlang.
> I found an example code :
>
> connect(Message) ->
>     Cmd = "./myqtwindowapp \n",
>     Port = open_port({spawn,Cmd}, [stream,use_stdio,exit_status]),
>     Payload = string:concat(Message, "\n"),
>     erlang:port_command(Port, Payload),
>     receive
>         {Port, {data, Data}} ->
>             ?DBG("Received data: ~p~n", [Data]),
>         Other ->
>             io:format("Unexpected data: ~p~n", [Other])
>     after 15000 ->
>             ?DBG("Received nothing~n", [])
>     end.
>  
>
> But i dont know how to run this code. I tried erl -run serv start but
> recieved error in do_boot. And how to include this code into a small module?
> Even i recieved error in dbg macros.
>
> Please help me. Suggest me how to finalize. I am newbie here, please suggest
> me how to run this code or other.
> Any help is appreciated.
>
> --
> View this message in context: http://erlang.2086793.n4.nabble.com/Erlang-gen-server-and-c-client-tp4655136.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions


Reply | Threaded
Open this post in threaded view
|

Erlang gen server and c++ client

techabc-2
hope tinch++ would help you:

tinch++: Interfacing Erlang from C++

http://www.adampetersen.se/code/tinchpp.htm

Introduction

tinch++ is a platform independent, open-source library for building
distributed Erlang nodes in C++. Distributed Erlang nodes provide a
high-level model for integrating other languages with Erlang programs.
With tinch++, your C++ code will be able to communicate with Erlang
processes by means of message passing. To the Erlang processes, your
C++ node will look and behave like any Erlang node.

Besides integrating C++ and Erlang programs, tinch++ may be used as a
thread-safe bidirectional queue between multiple threads in an
application. For an example, check out the example program
thread_safe_queue.cpp included in the tinch++ release.


2012/6/13 Serge Aleynikov <serge>:

> See this tutorial for help:
>
> http://trapexit.org/How_to_use_ei_to_marshal_binary_terms_in_port_programs
>
> On 6/13/2012 5:51 AM, benefit wrote:
>> Hello.
>> Please help me.
>> I need to make a erlang gen_server which works with an erlang port.
>> An c++ application must connect to erlang port and send a string. Server
>> should return the same string to the application.
>>
>> I have troubles working with erlang.
>> I found an example code :
>>
>> connect(Message) ->
>> ? ? Cmd = "./myqtwindowapp \n",
>> ? ? Port = open_port({spawn,Cmd}, [stream,use_stdio,exit_status]),
>> ? ? Payload = string:concat(Message, "\n"),
>> ? ? erlang:port_command(Port, Payload),
>> ? ? receive
>> ? ? ? ? {Port, {data, Data}} ->
>> ? ? ? ? ? ? ?DBG("Received data: ~p~n", [Data]),
>> ? ? ? ? Other ->
>> ? ? ? ? ? ? io:format("Unexpected data: ~p~n", [Other])
>> ? ? after 15000 ->
>> ? ? ? ? ? ? ?DBG("Received nothing~n", [])
>> ? ? end.
>>
>>
>> But i dont know how to run this code. I tried erl -run serv start but
>> recieved error in do_boot. And how to include this code into a small module?
>> Even i recieved error in dbg macros.
>>
>> Please help me. Suggest me how to finalize. I am newbie here, please suggest
>> me how to run this code or other.
>> Any help is appreciated.
>>
>> --
>> View this message in context: http://erlang.2086793.n4.nabble.com/Erlang-gen-server-and-c-client-tp4655136.html
>> Sent from the Erlang Questions mailing list archive at Nabble.com.
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions