Sophie

Sophie

distrib > Fedora > 17 > i386 > media > updates > by-pkgid > 675c8c8167236dfcf8d66da674f931e8 > files > 151

erlang-doc-R15B-03.3.fc17.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../otp_doc.css" type="text/css">
<title>Erlang -- Overview</title>
</head>
<body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container">
<script id="js" type="text/javascript" language="JavaScript" src="../js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript">
            <!--
              function getWinHeight() {
                var myHeight = 0;
                if( typeof( window.innerHeight ) == 'number' ) {
                  //Non-IE
                  myHeight = window.innerHeight;
                } else if( document.documentElement && ( document.documentElement.clientWidth ||
                                                         document.documentElement.clientHeight ) ) {
                  //IE 6+ in 'standards compliant mode'
                  myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                  //IE 4 compatible
                  myHeight = document.body.clientHeight;
                }
                return myHeight;
              }

              function setscrollpos() {
                var objf=document.getElementById('loadscrollpos');
                 document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2;
              }

              function addEvent(obj, evType, fn){
                if (obj.addEventListener){
                obj.addEventListener(evType, fn, true);
                return true;
              } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
              } else {
                return false;
              }
             }

             addEvent(window, 'load', setscrollpos);

             //--></script><div id="leftnav"><div class="innertube">
<img alt="Erlang logo" src="../erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="../pdf/otp-system-documentation-5.9.3.1.pdf">PDF</a><br><a href="../index.html">Top</a></small><p><strong>Interoperability Tutorial</strong><br><strong>User's Guide</strong><br><small>Version 5.9.3.1</small></p>
<br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p>
<ul class="flipMenu" imagepath="../js/flipmenu">
<li id="no" title="Introduction" expanded="false">Introduction<ul>
<li><a href="introduction.html">
              Top of chapter
            </a></li>
<li title="Purpose"><a href="introduction.html#id60800">Purpose</a></li>
<li title="Prerequisites"><a href="introduction.html#id60757">Prerequisites</a></li>
</ul>
</li>
<li id="loadscrollpos" title="Overview" expanded="true">Overview<ul>
<li><a href="overview.html">
              Top of chapter
            </a></li>
<li title="Built-In Mechanisms"><a href="overview.html#id62194">Built-In Mechanisms</a></li>
<li title="C and Java Libraries"><a href="overview.html#id60915">C and Java Libraries</a></li>
<li title="Standard Protocols"><a href="overview.html#id62774">Standard Protocols</a></li>
<li title="IC"><a href="overview.html#id61047">IC</a></li>
<li title="Old Applications"><a href="overview.html#id62555">Old Applications</a></li>
</ul>
</li>
<li id="no" title="Problem Example" expanded="false">Problem Example<ul>
<li><a href="example.html">
              Top of chapter
            </a></li>
<li title="Description"><a href="example.html#id63860">Description</a></li>
</ul>
</li>
<li id="no" title="Ports" expanded="false">Ports<ul>
<li><a href="c_port.html">
              Top of chapter
            </a></li>
<li title="Erlang Program"><a href="c_port.html#id58262">Erlang Program</a></li>
<li title="C Program"><a href="c_port.html#id62416">C Program</a></li>
<li title="Running the Example"><a href="c_port.html#id63496">Running the Example</a></li>
</ul>
</li>
<li id="no" title="Erl_Interface" expanded="false">Erl_Interface<ul>
<li><a href="erl_interface.html">
              Top of chapter
            </a></li>
<li title="Erlang Program"><a href="erl_interface.html#id63174">Erlang Program</a></li>
<li title="C Program"><a href="erl_interface.html#id63282">C Program</a></li>
<li title="Running the Example"><a href="erl_interface.html#id61784">Running the Example</a></li>
</ul>
</li>
<li id="no" title="Port drivers" expanded="false">Port drivers<ul>
<li><a href="c_portdriver.html">
              Top of chapter
            </a></li>
<li title="Port Drivers"><a href="c_portdriver.html#id61981">Port Drivers</a></li>
<li title="Erlang Program"><a href="c_portdriver.html#id62001">Erlang Program</a></li>
<li title="C Driver"><a href="c_portdriver.html#id62119">C Driver</a></li>
<li title="Running the Example"><a href="c_portdriver.html#id63970">Running the Example</a></li>
</ul>
</li>
<li id="no" title="C Nodes" expanded="false">C Nodes<ul>
<li><a href="cnode.html">
              Top of chapter
            </a></li>
<li title="Erlang Program"><a href="cnode.html#id64088">Erlang Program</a></li>
<li title="C Program"><a href="cnode.html#id64168">C Program</a></li>
<li title="Running the Example"><a href="cnode.html#id64499">Running the Example</a></li>
</ul>
</li>
<li id="no" title="NIFs" expanded="false">NIFs<ul>
<li><a href="nif.html">
              Top of chapter
            </a></li>
<li title="NIFs"><a href="nif.html#id64799">NIFs</a></li>
<li title="Erlang Program"><a href="nif.html#id64820">Erlang Program</a></li>
<li title="NIF library code"><a href="nif.html#id64884">NIF library code</a></li>
<li title="Running the Example"><a href="nif.html#id64985">Running the Example</a></li>
</ul>
</li>
</ul>
</div></div>
<div id="content">
<div class="innertube">
<h1>2 Overview</h1>
  

  <h3><a name="id62194">2.1 
        Built-In Mechanisms</a></h3>
    
    <p>There are two interoperability mechanisms built into the Erlang runtime system. One is <strong>distributed Erlang</strong> and the other one is <strong>ports</strong>. A variation of ports is <strong>linked-in drivers</strong>.</p>
    <a name="dist"></a>

    <h4>Distributed Erlang</h4>
      
      <p>An Erlang runtime system is made into a distributed Erlang node by giving it a name. A distributed Erlang node can connect to and monitor other nodes, it is also possible to spawn processes at other nodes. Message passing and error handling between processes at different nodes are transparent. There exists a number of useful <span class="code">stdlib</span> modules intended for use in a distributed Erlang system; for example, <span class="code">global</span> which provides global name registration. The distribution mechanism is implemented using TCP/IP sockets.</p>
      <p><strong>When to use:</strong> Distributed Erlang is primarily used for communication Erlang-Erlang. It can also be used for communication between Erlang and C, if the C program is implemented as a <span class="bold_code"><a href="#cnode">C node</a></span>, see below.</p>
      <p><strong>Where to read more:</strong> Distributed Erlang and some distributed programming techniques are described in the Erlang book.        <br>

        In the Erlang/OTP documentation there is a chapter about distributed Erlang in "Getting Started" (User's Guide).        <br>

        Relevant man pages are <span class="code">erlang</span> (describes the BIFs) and <span class="code">global</span>, <span class="code">net_adm</span>, <span class="code">pg2</span>, <span class="code">rpc</span>, <span class="code">pool</span> and <span class="code">slave</span>.</p>
    

    <h4>Ports and Linked-In Drivers</h4>
      
      <p>Ports provide the basic mechanism for communication with the external world, from Erlang's point of view. They provide a byte-oriented interface to an external program. When a port has been created, Erlang can communicate with it by sending and receiving lists of bytes (not Erlang terms). This means that the programmer may have to invent a suitable encoding and decoding scheme.</p>
      <p>The actual implementation of the port mechanism depends on the platform. In the Unix case, pipes are used and the external program should as default read from standard input and write to standard output. Theoretically, the external program could be written in any programming language as long as it can handle the interprocess communication mechanism with which the port is implemented.</p>
      <p>The external program resides in another OS process than the Erlang runtime system. In some cases this is not acceptable, consider for example drivers with very hard time requirements. It is therefore possible to write a program in C according to certain principles and dynamically link it to the Erlang runtime system, this is called a linked-in driver.</p>
      <p><strong>When to use:</strong> Being the basic mechanism, ports can be used for all kinds of interoperability situations where the Erlang program and the other program runs on the same machine. Programming is fairly straight-forward.        <br>

        Linked-in drivers involves writing certain call-back functions in C. Very good skills are required as the code is linked to the Erlang runtime system.</p>
      <div class="warning">
<div class="label">Warning</div>
<div class="content"><p>
        <p>An erroneous linked-in driver will cause the entire Erlang runtime system to leak memory, hang or crash.</p>
      </p></div>
</div>
      <p><strong>Where to read more:</strong> Ports are described in the "Miscellaneous Items" chapter of the Erlang book. Linked-in drivers are described in Appendix E.        <br>

        The BIF <span class="code">open_port/2</span> is documented in the man page for <span class="code">erlang</span>. For linked-in drivers, the programmer needs to read the information in the man page for <span class="code">erl_ddll</span>.</p>
      <p><strong>Examples:</strong><span class="bold_code"><a href="c_port.html">Port example</a></span>.</p>
    
  

  <h3><a name="id60915">2.2 
        C and Java Libraries</a></h3>
    

    <h4>Erl_Interface</h4>
      
      <p>Very often the program at the other side of a port is a C program. To help the C programmer a library called Erl_Interface has been developed. It consists of five parts:</p>
      <ul>
        <li>
<span class="code">erl_marshal</span>, <span class="code">erl_eterm</span>, <span class="code">erl_format</span>, <span class="code">erl_malloc</span> Handling of the Erlang external term format.</li>
        <li>
<span class="code">erl_connect</span> Communication with distributed Erlang, see <span class="bold_code"><a href="#cnode">C nodes</a></span> below.</li>
        <li>
<span class="code">erl_error</span> Error print routines.</li>
        <li>
<span class="code">erl_global</span> Access globally registered names.</li>
        <li>
<span class="code">Registry</span> Store and backup of key-value pairs.</li>
      </ul>
      <p>The Erlang external term format is a representation of an Erlang term as a sequence of bytes, a binary. Conversion between the two representations is done using BIFs.</p>
      <div class="example"><pre>
Binary = term_to_binary(Term)
Term = binary_to_term(Binary)</pre></div>
      <p>A port can be set to use binaries instead of lists of bytes. It is then not necessary to invent any encoding/decoding scheme. Erl_Interface functions are used for unpacking the binary and convert it into a struct similar to an Erlang term. Such a struct can be manipulated in different ways and be converted to the Erlang external format and sent to Erlang.</p>
      <p><strong>When to use:</strong> In C code, in conjunction with Erlang binaries.</p>
      <p><strong>Where to read more:</strong> Read about the Erl_Interface User's Guide; Command Reference and Library Reference. In R5B and earlier versions the information can be found under the Kernel application.</p>
    
    <p><strong>Examples:</strong><span class="bold_code"><a href="erl_interface.html">erl_interface example</a></span>.</p>
    <a name="cnode"></a>

    <h4>C Nodes</h4>
      
      <p>A C program which uses the Erl_Interface functions for setting up a connection to and communicating with a distributed Erlang node is called a <strong>C node</strong>, or a <strong>hidden node</strong>. The main advantage with a C node is that the communication from the Erlang programmer's point of view is extremely easy, since the C program behaves as a distributed Erlang node.</p>
      <p><strong>When to use:</strong> C nodes can typically be used on device processors (as opposed to control processors) where C is a better choice than Erlang due to memory limitations and/or application characteristics.</p>
      <p><strong>Where to read more:</strong> In the <span class="code">erl_connect</span> part of the Erl_Interface documentation, see above. The programmer also needs to be familiar with TCP/IP sockets, see <span class="bold_code"><a href="#sockets">below</a></span>, and distributed Erlang, see <span class="bold_code"><a href="#dist">above</a></span>.</p>
      <p><strong>Examples:</strong><span class="bold_code"><a href="cnode.html">C node example</a></span>.</p>
    

    <h4>Jinterface</h4>
      
      <p>In Erlang/OTP R6B, a library similar to Erl_Interface for Java was added called <strong>jinterface</strong>.</p>
    
  

  <h3><a name="id62774">2.3 
        Standard Protocols</a></h3>
    
    <p>Sometimes communication between an Erlang program and another program using a standard protocol is desirable. Erlang/OTP currently supports TCP/IP and UDP <strong>sockets</strong>, SNMP, HTTP and IIOP (CORBA). Using one of the latter three requires good knowledge about the protocol and is not covered by this tutorial. Please refer to the documentation for the SNMP, Inets and Orber applications, respectively.</p>
    <a name="sockets"></a>

    <h4>Sockets</h4>
      
      <p>Simply put, connection-oriented socket communication (TCP/IP) consists of an initiator socket ("server") started at a certain host with a certain port number. A connector socket ("client") aware of the initiator's host name and port number can connect to it and data can be sent between them. Connection-less socket communication (UDP) consists of an initiator socket at a certain host with a certain port number and a connector socket sending data to it. For a detailed description of the socket concept, please refer to a suitable book about network programming. A suggestion is <strong>UNIX Network Programming, Volume 1: Networking APIs - Sockets and XTI</strong> by W. Richard Stevens, ISBN: 013490012X.</p>
      <p>In Erlang/OTP, access to TCP/IP and UDP sockets is provided by the 
        Kernel modules <span class="code">gen_tcp</span> and <span class="code">gen_udp</span>. Both are easy to 
        use and do not require any deeper knowledge about the socket concept.</p>
      <p><strong>When to use:</strong> For programs running on the same or on another machine than the Erlang program.</p>
      <p><strong>Where to read more:</strong> The man pages for <span class="code">gen_tcp</span> and <span class="code">gen_udp</span>.</p>
    
  

  <h3><a name="id61047">2.4 
        IC</a></h3>
    
    <p>IC (IDL Compiler) is an interface generator which given an IDL interface specification automatically generates stub code in Erlang, C or Java. Please refer to the IC User's Guide and IC Reference Manual.</p>
  

  <h3><a name="id62555">2.5 
        Old Applications</a></h3>
    
    <p>There are two old applications of interest when talking about interoperability: <strong>IG</strong> which was removed in Erlang/OTP R6B and <strong>Jive</strong> which was removed in Erlang/OTP R7B. Both applications have been replaced by IC and are mentioned here for reference only.</p>
    <p>IG (Interface Generator) automatically generated code for port or socket communication between an Erlang program and a C program, given a C header file with certain keywords. Jive provided a simple interface between an Erlang program and a Java program.</p>
  
</div>
<div class="footer">
<hr>
<p>Copyright © 2000-2012 Ericsson AB. All Rights Reserved.</p>
</div>
</div>
</div></body>
</html>