Tutorial (Erlang / Python)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Tutorial (Erlang / Python)

Walter Weinmann
What is the idea behind the examples in the tutorial? Should these be executable or are they just non-executable program code patterns. I want to use Apache Thrift to connect Erlang and Python, but I am struggling with connection problems from Erlang Client to Python Server (see THRIFT-4312 or Apache Thrift mailing list). Since the community is very quiet here, I'm afraid this is a much too exotic combination for Apache Thrift. Any comments?

Thanks and regards

Walter

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Tutorial (Erlang / Python)

zxq9-2
On 2017年09月13日 水曜日 08:42:27 Walter Weinmann wrote:
> What is the idea behind the examples in the tutorial? Should these be
> executable or are they just non-executable program code patterns. I want to
> use Apache Thrift to connect Erlang and Python, but I am struggling with
> connection problems from Erlang Client to Python Server (see THRIFT-4312
> <https://issues.apache.org/jira/browse/THRIFT-4312> or Apache Thrift
> mailing list
> <http://mail-archives.apache.org/mod_mbox/thrift-user/201709.mbox/<CACe_jXefCS6pR-6YoZ6nMNU4y89KDiu2cnFi3dj6k%2BPpGaBrfQ%40mail.gmail.com>>).
> Since the community is very quiet here, I'm afraid this is a much too
> exotic combination for Apache Thrift. Any comments?

I'm not familiar with Apache Thrift. Normally when I want Python and Erlang to talk to one another I use BERT over a socket (usually network socket, but anything works). But that is just old-fashioned socket programming.

Looking at the docs for Thrift[1] it looks like there is supposed to be something like a Thrift compiler that builds an Erlang (and Python and whatever else) module for you that you should be invoking. I assume that is the `thrift_client` module you are invoking in your program.

The error you are seeing there with {error, econnrefused} is a normal TCP network error, not a specific Thrift/Erlang problem -- so check that the service you're trying to connect to is running and the port you're trying to contact is open.

It seems very odd that the return value of `thrift_client:call/2` is being assigned to `Client1,2,3`. Are you sure the return value is supposed to look like this? Once you get the network problem sorted out, give that part a look -- I imagine that's actually supposed to always match the original Client (so that maybe you could open several connections at once, and match on them in a larger `receive` or `case` clause.

-Craig

[1] It looks like your formatting for Jira got sort of crazy at some point, so its a little hard to tell how things were supposed to be formatted. Pasting your example in a paste bin or here in the mailing list could be helpful.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Tutorial (Erlang / Python)

Walter Weinmann
Hi Craig, thanks for the answer.

I have a repository in Github with the complete test environment based on the Erlang and Python examples from the Thrift tutorial. Of course, the corresponding program parts were also generated by the Thrift compiler. The Python server is also ok and can be reached via the Python client. The Erlang server can be accessed via both clients (Erlang and Python). Only the connection from the Erlang Client to the Python server is not established. Of course, it's the kind of connection I need first.   

Apache Thrift sounds really good, as it theoretically connects a lot of platforms.

On 13 September 2017 at 09:07, zxq9 <[hidden email]> wrote:
On 2017年09月13日 水曜日 08:42:27 Walter Weinmann wrote:
> What is the idea behind the examples in the tutorial? Should these be
> executable or are they just non-executable program code patterns. I want to
> use Apache Thrift to connect Erlang and Python, but I am struggling with
> connection problems from Erlang Client to Python Server (see THRIFT-4312
> <https://issues.apache.org/jira/browse/THRIFT-4312> or Apache Thrift
> mailing list
> <http://mail-archives.apache.org/mod_mbox/thrift-user/201709.mbox/<CACe_jXefCS6pR-6YoZ6nMNU4y89KDiu2cnFi3dj6k%2BPpGaBrfQ%40mail.gmail.com>>).
> Since the community is very quiet here, I'm afraid this is a much too
> exotic combination for Apache Thrift. Any comments?

I'm not familiar with Apache Thrift. Normally when I want Python and Erlang to talk to one another I use BERT over a socket (usually network socket, but anything works). But that is just old-fashioned socket programming.

Looking at the docs for Thrift[1] it looks like there is supposed to be something like a Thrift compiler that builds an Erlang (and Python and whatever else) module for you that you should be invoking. I assume that is the `thrift_client` module you are invoking in your program.

The error you are seeing there with {error, econnrefused} is a normal TCP network error, not a specific Thrift/Erlang problem -- so check that the service you're trying to connect to is running and the port you're trying to contact is open.

It seems very odd that the return value of `thrift_client:call/2` is being assigned to `Client1,2,3`. Are you sure the return value is supposed to look like this? Once you get the network problem sorted out, give that part a look -- I imagine that's actually supposed to always match the original Client (so that maybe you could open several connections at once, and match on them in a larger `receive` or `case` clause.

-Craig

[1] It looks like your formatting for Jira got sort of crazy at some point, so its a little hard to tell how things were supposed to be formatted. Pasting your example in a paste bin or here in the mailing list could be helpful.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Tutorial (Erlang / Python)

zxq9-2
On 2017年09月13日 水曜日 09:29:45 you wrote:

> Hi Craig, thanks for the answer.
>
> I have a repository in Github
> <https://github.com/walter-weinmann/erlang_thrift_tutorial> with the
> complete test environment based on the Erlang and Python examples from the
> Thrift tutorial. Of course, the corresponding program parts were also
> generated by the Thrift compiler. The Python server is also ok and can be
> reached via the Python client. The Erlang server can be accessed via both
> clients (Erlang and Python). Only the connection from the Erlang Client to
> the Python server is not established. Of course, it's the kind of
> connection I need first.
>
> Apache Thrift sounds really good, as it theoretically connects a lot of
> platforms.

If the Python client can talk to the Python service over the network without any problem, the perhaps the generated Erlang code has a runtime dependency on inets or something similar.

Try something like this:

    t() ->
        {ok, Client} = connect(9090),
        % ... whatever else you were going to do.


    connect(Port) ->
        ok = application:ensure_started(inets),
        thrift_client_util:new("localhost", Port, calculator_thrift, []).

Also, each time you receive a response from the call/3 function, check if the received `Client1,2,3` values are actually the same as the original `Client` value returned by `thrift_client_util:connect/4`. Also check if there are any additional start or init functions that are supposed to be called in thrift_client or thrift_client_util to get things set up (some init functions may take care of things like starting dependencies).

-Craig
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Tutorial (Erlang / Python)

Walter Weinmann
No problem with: 

ok = application:ensure_started(inets),

but still:

** exception error: no match of right hand side value {error,econnrefused}
     in function  client:t/0 (d:/SoftDevelopment/Projects/erlang_thrift_tutorial
_idea/erlang_thrift_tutorial/_build/default/lib/tutorial/src/client.erl, line 43

with:

{ok, Client0} = connect(Port),

respectively:

connect(Port) ->
    ok = application:ensure_started(inets),
io:format("inets~n", []),
thrift_client_util:new("localhost", Port, calculator_thrift, []).

Walter

On 13 September 2017 at 09:58, zxq9 <[hidden email]> wrote:
On 2017年09月13日 水曜日 09:29:45 you wrote:
> Hi Craig, thanks for the answer.
>
> I have a repository in Github
> <https://github.com/walter-weinmann/erlang_thrift_tutorial> with the
> complete test environment based on the Erlang and Python examples from the
> Thrift tutorial. Of course, the corresponding program parts were also
> generated by the Thrift compiler. The Python server is also ok and can be
> reached via the Python client. The Erlang server can be accessed via both
> clients (Erlang and Python). Only the connection from the Erlang Client to
> the Python server is not established. Of course, it's the kind of
> connection I need first.
>
> Apache Thrift sounds really good, as it theoretically connects a lot of
> platforms.

If the Python client can talk to the Python service over the network without any problem, the perhaps the generated Erlang code has a runtime dependency on inets or something similar.

Try something like this:

    t() ->
        {ok, Client} = connect(9090),
        % ... whatever else you were going to do.


    connect(Port) ->
        ok = application:ensure_started(inets),
        thrift_client_util:new("localhost", Port, calculator_thrift, []).

Also, each time you receive a response from the call/3 function, check if the received `Client1,2,3` values are actually the same as the original `Client` value returned by `thrift_client_util:connect/4`. Also check if there are any additional start or init functions that are supposed to be called in thrift_client or thrift_client_util to get things set up (some init functions may take care of things like starting dependencies).

-Craig
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Tutorial (Erlang / Python)

zxq9-2
On 2017年09月13日 水曜日 10:49:42 Walter Weinmann wrote:
> {error,econnrefused}

What happens if you do (in your shell):

  telnet localhost 9090

And in an Erlang shell

  gen_tcp:connect("localhost", 9090).

?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Tutorial (Erlang / Python)

zxq9-2
On 2017年09月13日 水曜日 17:54:32 zxq9 wrote:
>
>   gen_tcp:connect("localhost", 9090).

HA HA HA! Sorry, spectators, that was not supposed to be a practical joke...

    gen_tcp:connect("localhost", 9090, []).

Walter was kind and wrote me off-list to let me know that this didn't work, not realizing that my mistakes tend to come right out in public most of the time in any case.

Dhoh!

-Craig
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions