Difference between revisions of "Networking/fr"

From Free Pascal wiki
Jump to navigationJump to search
 
(15 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
== D'autres tutoriels sur la gestion de réseaux ==  
 
== D'autres tutoriels sur la gestion de réseaux ==  
  
* [[Secure programming | Programmation en sureté ]]  
+
* [[Secure programming/fr| Programmation en sureté ]]  
  
* [[Sockets|Sockets]] - TCP/IP Sockets components
+
* [[Sockets|Sockets]] - composants permettant une interface logicielle(Sockets) avec les services du système d'exploitation pour utiliser le protocole reseau TCP/IP  
  
* [[lNet|lNet]] - Lightweight Networking Components
+
* [[lNet|lNet]] - composants de gestion de reseau Léger
  
== TCP/IP Protocol ==
+
* [[XML Tutorial/fr|Tutoriel XML]] - XML est souvent utilisé avec les communications de réseau
  
== XML ==
+
== Le protocole TCP/IP ==
  
The Extensible Markup Language is a [http://www.w3.org/ W3C] recommended language created to interchange information between different systems. It is a text based way to store information. Modern data interchange languages such as XHTML, as well as most WebServices technologies, are based on XML.
 
  
Currently there is a set of units that provides support for XML on Lazarus. These units are called "XMLRead", "XMLWrite" and "DOM" and they are part of the Free Component Library (FCL) from the Free Pascal Compiler. The FCL is already on the default search path for the compiler on Lazarus, so you only need to add the units to your uses clause in order to get XML support. The FCL is not documented currently (October / 2005), so this short tutorial aims at introducing XML access using those units.
+
== WebServices ==
 
 
The XML DOM (Document Object Model) is a set of standarized objects that provide a similar interface for the use of XML on different languages and systems. The standard only specifies the methods, properties and other interface parts of the object, leaving the implementation free for different languages. The FCL currently supports fully the [http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/ XML DOM 1.0].
 
 
 
=== Basic Example ===
 
 
 
For Delphi Programmers:
 
Note that when working with TXMLDocument, the text within a Node is considered a separate TEXT Node.  As a result, you must access a node's text value as a separate node.  For instance, consider the following XML:
 
 
 
<code>
 
<?xml version="1.0" encoding="utf-8"?>
 
<request>
 
  <request_type>PUT_FILE</request_type>
 
  <username>123</username>
 
  <password>abc</password>
 
</request>
 
</code>
 
 
 
Consider also the following code example:
 
 
 
<code>
 
var
 
  PassNode: TDOMNode;
 
  Doc:      TXMLDocument;
 
begin
 
  Doc := TXMLDocument.Create;
 
  // Read in xml file from disk
 
  ReadXMLFile(Doc, 'c:\xmlfiles\test.xml');
 
  // Retrieve the "password" node
 
  PassNode := Doc.DocumentElement.FindNode('password');
 
  // Write out value of the selected node
 
  WriteLn(PassNode.NodeValue); // will be blank
 
  // The text of the node is actually a separate child node
 
  WriteLn(PassNode.FirstChild.NodeValue); // correctly prints "abc"
 
</code>
 
 
 
 
 
Let´s say you want to access a XML file called 'C:\Programas\teste.xml'. Here is the file content:
 
 
 
<code>
 
<?xml version="1.0" encoding="ISO-8859-1"?>
 
<images directory="mydir">
 
  <imageNode URL="graphic.jpg" title="">
 
    <Peca DestinoX="0" DestinoY="0">Pecacastelo.jpg1.swf</Peca>
 
    <Peca DestinoX="0" DestinoY="86">Pecacastelo.jpg2.swf</Peca>
 
  </imageNode>
 
</images>
 
</code>
 
 
 
The following code can write the Node´s names to a TMemo placed on a form:
 
 
 
<code>
 
var
 
  Documento: TXMLDocument;
 
  i, j: Integer;
 
begin
 
  Documento := TXMLDocument.Create;
 
  ReadXMLFile(Documento, 'C:\Programas\teste.xml');
 
  Memo.Lines.Clear;
 
  with Documento.DocumentElement.ChildNodes do
 
  begin
 
    for i := 0 to (Count - 1) do
 
    begin
 
      Memo.Lines.Add(Item[i].NodeName + ' ' + Item[i].NodeValue);
 
      for j := 0 to (Item[i].ChildNodes.Count - 1) do
 
      begin
 
        Memo.Lines.Add(Item[i].ChildNodes.Item[j].NodeName + ' '
 
        + Item[i].ChildNodes.Item[j].NodeValue);
 
      end;
 
    end;
 
  end;
 
  Documento.Free;
 
end;
 
</code>
 
 
 
=== Populating a TreeView with XML ===
 
 
 
One common use of XML files is to parse them and show their contents in a tree like format. You can find the TTreeView component on the "Common Controls" tab on Lazarus.
 
 
 
The function below will take a XML document previously loaded from a file or generated on code, and will populate a TreeView with it´s contents. The caption of each node will be the content of the first attribute of each node.
 
 
 
<pre>
 
procedure TForm1.XML2Tree(tree: TTreeView; XMLDoc: TXMLDocument);
 
var
 
  iNode: TDOMNode;
 
 
 
  procedure ProcessNode(Node: TDOMNode; TreeNode: TTreeNode);
 
  var
 
    cNode: TDOMNode;
 
  begin
 
    if Node = nil then Exit; // Stops if reached a leaf
 
   
 
    // Adds a node to the tree
 
    TreeNode := tree.Items.AddChild(TreeNode, Node.Attributes[0].NodeValue);
 
 
 
    // Goes to the child node
 
    cNode := Node.ChildNodes.Item[0];
 
  
    // Processes all child nodes
+
Selon  [http://www.w3.org/ W3C] un service web est un système logiciel conçu pour soutenir les intéractions de machine à machine interoperable sur un réseau. Il a une interface qui est décrite dans un format exploitable par une machine comme WSDL(Web Service Description Langage = Langage de description de Services Web).  
    while cNode <> nil do
 
    begin
 
      ProcessNoDe(cNode, TreeNode);
 
      cNode := cNode.NextSibling;
 
    end;
 
  end;
 
   
 
begin
 
  iNode := XMLDoc.DocumentElement.ChildNodes.Item[0];
 
  while iNode <> nil do
 
  begin
 
    ProcessNode(iNode, nil); // Recursive
 
    iNode := iNode.NextSibling;
 
  end;
 
end;
 
</pre>
 
 
 
=== Modifying a XML document ===
 
 
 
The first thing to remember is that TDOMDocument is the "handle" to the DOM. You can get an instance of this class by creating one or by loading a XML document.
 
 
 
Nodes on the other hand cannot be created like a normal object. You *must* use the methods provided by TDOMDocument to create them, and latter use other methods to put them on the correct place on the tree. This is because nodes must be "owned" by a specific document on DOM.
 
 
 
Below are some common methods from TDOMDocument:
 
 
 
<pre>
 
  function CreateElement(const tagName: DOMString): TDOMElement; virtual;
 
  function CreateTextNode(const data: DOMString): TDOMText;
 
  function CreateCDATASection(const data: DOMString): TDOMCDATASection;
 
    virtual;
 
  function CreateAttribute(const name: DOMString): TDOMAttr; virtual;
 
</pre>
 
 
 
And here an example method that will located the selected item on a TTreeView and then insert a child node to the XML document it represents. The TreeView must be previously filled with the contents of a XML file using the [[Networking/fr#Populating a TreeView with XML|fonction XML2Tree]].
 
 
 
<pre>
 
procedure TForm1.actAddChildNode(Sender: TObject);
 
var
 
  Posicao: Integer;
 
  NovoNo: TDomNode;
 
begin
 
  {*******************************************************************
 
  *  Detects the selected element
 
  *******************************************************************}
 
  if TreeView1.Selected = nil then Exit;
 
 
 
  if TreeView1.Selected.Level = 0 then
 
  begin
 
    Posicao := TreeView1.Selected.Index;
 
 
 
    NovoNo := XMLDoc.CreateElement('item');
 
    TDOMElement(NovoNo).SetAttribute('nome', 'Item');
 
    TDOMElement(NovoNo).SetAttribute('arquivo', 'Arquivo');
 
    XMLDoc.DocumentElement.ChildNodes.Item[Posicao].AppendChild(NovoNo);
 
 
 
    {*******************************************************************
 
    *  Updates the TreeView
 
    *******************************************************************}
 
    TreeView1.Items.Clear;
 
    XML2Tree(TreeView1, XMLDoc);
 
  end
 
  else if TreeView1.Selected.Level >= 1 then
 
  begin
 
    {*******************************************************************
 
    *  This function only works on the first level of the tree,
 
    *  but can easely modifyed to work for any number of levels
 
    *******************************************************************}
 
  end;
 
end;
 
</pre>
 
 
 
=== Create a TXMLDocument from a string ===
 
 
 
Given al XML file in MyXmlString, the following code will create it's DOM:
 
 
 
<pre>
 
Var
 
  S : TStringStream;
 
  XML : TXMLDocument;
 
 
 
begin
 
  S:= TStringStream.Create(MyXMLString);
 
  Try
 
    S.Position:=0;
 
    XML:=Nil;
 
    ReadXMLFile(XML,S); // Complete XML document
 
    // Alternatively:
 
    ReadXMLFragment(AParentNode,S); // Read only XML fragment.
 
  Finally
 
    S.Free;
 
  end;
 
end;
 
</pre>
 
 
 
== WebServices ==
 
  
According to the [http://www.w3.org/ W3C] a Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface that is described in a machine-processable format such as WSDL. Other systems interact with the Web service in a manner prescribed by its interface using messages, which may be enclosed in a SOAP envelope, or follow a REST approach. These messages are typically conveyed using HTTP, and are normally comprised of XML in conjunction with other Web-related standards. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks like the Internet in a manner similar to inter-process communication on a single computer. This interoperability (e.g., between Windows and Linux applications) is due to the use of open standards. OASIS and the W3C are the primary committees responsible for the architecture and standardization of web services. To improve interoperability between web service implementations, the WS-I organisation has been developing a series of profiles to further define the standards involved.
+
D'autre systèmes interragissent avec le service web de la façon prescrite par son interface en utilisant des messages, qui peuvent être enfermé sous enveloppe SOAP(Simple Object Access Protocol), ou suivre l'approche REST . Ces messages sont typiquement transportés en utilisant l'HTTP,et sont normalement composés de  XML en même temps que d'autres normes Web-connexes . Des applications logiciel écrites dans divers langages de programmation  et s'executant sur diverses plate-formes peuvent utiliser les services web pour échanger des données sur des réseaux informatiques comme l'Internet de manière semblable à la communication interprocessus sur un unique ordinateur. Cette interopérabilité  (par exemple, entre les applications Windows et Linux ) est dû à l'utilisation de normes ouvertes. OASIS et  W3C sont les principaux comités  responsables pour l'architecture et la standardisation des services Web. Pour améliorer l'interopérabilité entre les réalisations de service web , l'organisation WS-I avait développé une série de profils pour davantage définir les normes  impliquées .
  
=== Web Service Toolkit for FPC & Lazarus ===
+
=== Trousse à outils de service Web pour  FPC & Lazarus ===
[[Web Service Toolkit]] is a web services package for FPC and Lazarus.
+
[[Web Service Toolkit/fr|Web Service Toolkit]] est un paquet de services web pour FPC et Lazarus.
  
== External Links ==
+
== Liens externes  ==
  
 
'''XML'''
 
'''XML'''
  
* [http://www.w3schools.com/xml/default.asp W3Schools] Xml Tutorial
+
* [http://www.w3schools.com/xml/default.asp W3Schools] est un tutoriel sur l'XML
  
* [http://www.thomas-zastrow.de/texte/fpcxml/index.php Thomas Zastrow article] FPC and XML
+
* [http://www.thomas-zastrow.de/texte/fpcxml/index.php article de Thomas Zastrow] sur FPC et XML

Latest revision as of 17:35, 9 July 2007

Deutsch (de) English (en) español (es) français (fr) 日本語 (ja) 한국어 (ko) polski (pl) português (pt) русский (ru) slovenčina (sk) 中文(中国大陆)‎ (zh_CN)

Cette page sera le début de tutoriels en rapport avec la programmation de reseaux avec Lazarus. Je ne suis pas un expert en programmation de gestion de réseau et je complèterais si j'en apprend davantage. J'invite d'autres gens à aider à la création d'articles sur la gestion de réseau . Ajouter juste un lien vers la prochaine section , ajouter une page et créer votre propre article WiKi . Sur cette page quelques informations générales seront données.

D'autres tutoriels sur la gestion de réseaux

  • Sockets - composants permettant une interface logicielle(Sockets) avec les services du système d'exploitation pour utiliser le protocole reseau TCP/IP
  • lNet - composants de gestion de reseau Léger
  • Tutoriel XML - XML est souvent utilisé avec les communications de réseau

Le protocole TCP/IP

WebServices

Selon W3C un service web est un système logiciel conçu pour soutenir les intéractions de machine à machine interoperable sur un réseau. Il a une interface qui est décrite dans un format exploitable par une machine comme WSDL(Web Service Description Langage = Langage de description de Services Web).

D'autre systèmes interragissent avec le service web de la façon prescrite par son interface en utilisant des messages, qui peuvent être enfermé sous enveloppe SOAP(Simple Object Access Protocol), ou suivre l'approche REST . Ces messages sont typiquement transportés en utilisant l'HTTP,et sont normalement composés de XML en même temps que d'autres normes Web-connexes . Des applications logiciel écrites dans divers langages de programmation et s'executant sur diverses plate-formes peuvent utiliser les services web pour échanger des données sur des réseaux informatiques comme l'Internet de manière semblable à la communication interprocessus sur un unique ordinateur. Cette interopérabilité (par exemple, entre les applications Windows et Linux ) est dû à l'utilisation de normes ouvertes. OASIS et W3C sont les principaux comités responsables pour l'architecture et la standardisation des services Web. Pour améliorer l'interopérabilité entre les réalisations de service web , l'organisation WS-I avait développé une série de profils pour davantage définir les normes impliquées .

Trousse à outils de service Web pour FPC & Lazarus

Web Service Toolkit est un paquet de services web pour FPC et Lazarus.

Liens externes

XML