<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'Erlang Python Example' | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/27/topics/390</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>Erlang Python Example posted by Alain O'Dea @ Wed, 07 May 2008 02:00:05 -0000</title>
      <description>&lt;p&gt;Very nice Stephan. Thank you for posting that. I was looking for a cleaner way to do communication between Erlang and Python. I could not figure out how to make Python implementation for the ports example.&lt;/p&gt;


	&lt;p&gt;Until now I have been using &lt;span class="caps"&gt;TCP&lt;/span&gt;/IP line-based communication. I could not figure out how to get the packet size thing to work. If you are interested I have included my old approach below.&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;TCP&lt;/span&gt; line-based integration with Erlang:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;-module (echo_server).
-export([start/0]).

start() -&amp;gt;
    {ok, Listen} = gen_tcp:listen(4321, [list, {packet, line},
                                         {reuseaddr, true},
                                         {active, true}]),
    spawn(fun() -&amp;gt; par_connect(Listen) end).

par_connect(Listen) -&amp;gt;
    {ok, Socket} = gen_tcp:accept(Listen),
    spawn(fun() -&amp;gt; par_connect(Listen) end),
    io:format("Client connected~n"),
    echo(Socket). 

echo(Socket) -&amp;gt;
    receive
        {tcp, Socket, Line} -&amp;gt;
            gen_tcp:send(Socket, Line),
            echo(Socket);
        {tcp_closed, Socket} -&amp;gt;
            io:format("Client disconnected~n")
    end.&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;Telnet can then be used to test the interface: &lt;code&gt;telnet 127.0.0.1 4321&lt;/code&gt;. Once you are satisfied it is very easy to build a &lt;span class="caps"&gt;TCP&lt;/span&gt; client in Python. I used this to implement a very basic Erlang code completion server for use with TextMate.&lt;/p&gt;</description>
      <pubDate>Wed, 07 May 2008 02:00:05 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:390:2745</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/390</link>
    </item>
    <item>
      <title>Erlang Python Example posted by Stephan Nies @ Mon, 28 Apr 2008 12:22:33 -0000</title>
      <description>&lt;p&gt;Hello, &lt;br /&gt;I am just learning Erlang. But since much of my&lt;br /&gt;codebase is in Python i wanted to interface Erlang and&lt;br /&gt;Python. So i ported the ports example in Chapter 12.1 to Python.&lt;/p&gt;


	&lt;p&gt;I thought that might be of interest for some other &lt;br /&gt;people using Erlang and Python. So here is the link:&lt;/p&gt;


	&lt;p&gt;&amp;#8220;http://www.physik.uni-dortmund.de/~nies/example1.py&amp;#8221;&lt;/p&gt;


	&lt;p&gt;You can just use it as a replacement for the C-code,&lt;br /&gt;just make sure to rename it to example1, make it executeable&lt;br /&gt;and place it in the same dir as example1.erl&lt;/p&gt;


	&lt;p&gt;Oh and while searching the net for python &amp;lt;-&amp;gt; erlang examples&lt;br /&gt;I found this neat project using twisted to interface with erlang: &lt;a href="https://launchpad.net/twotp"&gt;https://launchpad.net/twotp&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Cheers,&lt;br /&gt;Stephan&lt;/p&gt;</description>
      <pubDate>Mon, 28 Apr 2008 12:22:33 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:390:2661</guid>
      <author>Stephan Nies</author>
      <link>http://forums.pragprog.com/forums/27/topics/390</link>
    </item>
  </channel>
</rss>
