Difference between revisions of "Networking/ja"

From Free Pascal wiki
Jump to navigationJump to search
m (Text replace - "delphi>" to "syntaxhighlight>")
Line 1: Line 1:
 
{{Networking}}
 
{{Networking}}
  
 +
{{Japanese Menu}}
  
{{Japanese Menu}}
+
このページは、Lazarus と 平易な FPC を用いたネットワークプログラムについての情報とチュートリアル/コードのページです。(訳注:最初にこの元記事を書いた人はネットワークプログラミングの専門でなく、独学で勉強したことを書いているそうです)
  
このページは、Lazarusでのネットワークプログラムについてのチュートリアルを開始するページになるでしょう。この記事に、リンクやセクション、ページ、あなたのWikiへのリンクを追加していってください。このページには、一般的な情報があります。
+
== TCP/IP プロトコル ==
  
(訳注:最初にこの元記事を書いた人はネットワークプログラミングの専門でなく、独学で勉強したことを書いているそうです)
+
{{Note|FPC/Lazarus には、ネットワーキングの機能を使うための様々なライブラリ(Synapse, lnet, fphttpclient, Indy,...)があるため、それらのライブラリに対して、多くの例が記述できると思います。 したがって、you may see the same examples multiple times - for different libraries. Have a look at the [http://brookframework.org] or [https://bitbucket.org/reiniero/fpctwit] frameworks for examples on how to build frameworks that can use multiple network libraries}}
  
__TOC__
+
=== CGI/FastCGI - REST, CRUD, チャットやブログ、ウェブページなど ===
== その他のネットワークのチュートリアル ==
 
  
* [[Secure programming | セキュア・プログラミング]]  
+
これらの機能は [[fcl-web]] を使うことで可能となります。 また、 Brook フレームワーク( [http://silvioprog.github.io/brookframework this page] )でも実装されています。
* [[Sockets]] - TCP/IP ソケットコンポーネント
 
* [[lNet]] - 軽量ネットワークコンポーネント
 
* [[XML Tutorial/ja]] - XML はしばしばネットワーク通信で用いられます
 
* [[FPC and Apache Modules]]
 
  
== TCP/IP Protocol ==
+
=== SSH/Telnet クライアント、メールの送信、ファイルのダウンロードや OAuth v1.0 の例 ===
 +
[[Synapse]]のページをご覧ください。
  
=== Webserver example ===
+
=== Webサーバの例 ===
  
 
以下は Synapse ライブラリを用いて記述した http サーバの例です。Mac OS Xでテストしました。ただし、Mac OS Xの socket ユニットでは定数 MSG_NOSIGNAL が定義されていないため、Synapse のソースに定数定義 MSG_NOSIGNAL = $20000 を追加してコンパイルしました(訳注 : 2010年9月現在SVNで流れている Synapse の新バージョンでは、上記の定数が追加されており、無修正でコンパイルできます)。
 
以下は Synapse ライブラリを用いて記述した http サーバの例です。Mac OS Xでテストしました。ただし、Mac OS Xの socket ユニットでは定数 MSG_NOSIGNAL が定義されていないため、Synapse のソースに定数定義 MSG_NOSIGNAL = $20000 を追加してコンパイルしました(訳注 : 2010年9月現在SVNで流れている Synapse の新バージョンでは、上記の定数が追加されており、無修正でコンパイルできます)。
Line 128: Line 125:
 
end.
 
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
=== TCP/IP Client - Server Example using built-in FCL-Net components ===
 +
 +
Please have a look at [http://pascalgeek.blogspot.com/2012/06/encryption-decryption-and-asynchronous.html this blog post].
 +
 +
=== Download HTTP page body, web server upload using POST, get external IP address ===
 +
These examples (using the FPC/Lazarus built in fphttpclient) can be found at [[fphttpclient#Examples]]
  
 
== Webサービス ==
 
== Webサービス ==
  
W3CによるWEBサービスはネットワークの上のマシンから、別のマシンへ、共通的に利用できるように設計されたソフトウェア・システムの名称です。
+
[http://www.w3.org/ W3C] によると、 Web サービスとは ネットワーク越しに機械と機械を相互に利用できるように設計されたソフトウェアの名称です。
 +
 
 +
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.
 +
 
 
WEBサービスには、WSDLなど、「機械が処理可能」な形式で記述されているインタフェースがあります。
 
WEBサービスには、WSDLなど、「機械が処理可能」な形式で記述されているインタフェースがあります。
 
また、他のシステムは、多くの場合、インタフェースによってSOAPに内包されるメッセージを使用し定められた方法でウェブサービスと対話します。もしくは、RESTによる方法を取るかもしれません。
 
また、他のシステムは、多くの場合、インタフェースによってSOAPに内包されるメッセージを使用し定められた方法でウェブサービスと対話します。もしくは、RESTによる方法を取るかもしれません。
Line 143: Line 151:
 
ウェブサービス実装間の相互運用性を改良するため、WS-I委員会は、さらに定義する一連のプロフィールを規格の関連の開発をしています。  
 
ウェブサービス実装間の相互運用性を改良するため、WS-I委員会は、さらに定義する一連のプロフィールを規格の関連の開発をしています。  
  
=== FPC & Lazarus のWeb Service Toolkit===
+
=== FPC & Lazarus のための Web サービスツールキット ===
[[Web Service Toolkit]] はFPCとLazarusのWEBサービスのパッケージです。
+
[[Web Service Toolkit]] は FPC と Lazarus のための WEBサービス のパッケージです。
  
== External Links ==
+
== 以下もご参照ください ==
 +
* [[Portal:Web Development|Web Development Portal]]
 +
* [[Networking libraries]] - comparison of various networking libraries
 +
* [http://brookframework.org Brook Framework] - The perfect Free Pascal framework for your web applications. It's pure Pascal. You don't need to leave your preferred programming language.
 +
* [http://www.fastplaz.com FastPlaz] - Fast Web Framework for pascal. More features like theme/templating, simple Model, session, mailer, etc.
 +
* [[Sockets]] - TCP/IP ソケットコンポーネント
 +
* [[fcl-net]] - Networking library supplied with FPC
 +
* [[lNet]] - 軽量ネットワークコンポーネント
 +
* [[Synapse]] - Serial port and synchronous TCP/IP Library
 +
* [[XML Tutorial/ja]] - XML はしばしばネットワーク通信で用いられます
 +
* [[FPC and Apache Modules]]
 +
* [[fcl-web]] - Also known as fpWeb, this is a library to develop web applications which can be deployed as cgi, fastcgi or apache modules.
 +
* [[Secure programming | セキュア・プログラミング]]
 +
* [[Internet Tools]] - A wrapper around Synapse/wininet/Android's httpcomponents simplifying https and redirections, and a XPath/XQuery/CSS Selector/JSONiq engine to process the downloaded pages
  
'''XML'''
 
  
* [http://www.w3schools.com/xml/default.asp W3Schools] Xml Tutorial
+
[[Category:Tutorials/ja]]
 +
[[Category:Networking/ja]]
 +
[[Category:FPC/ja]]
 +
[[Category:Lazarus/ja]]

Revision as of 15:43, 4 June 2016

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

日本語版メニュー
メインページ - Lazarus Documentation日本語版 - 翻訳ノート - 日本語障害情報

このページは、Lazarus と 平易な FPC を用いたネットワークプログラムについての情報とチュートリアル/コードのページです。(訳注:最初にこの元記事を書いた人はネットワークプログラミングの専門でなく、独学で勉強したことを書いているそうです)

TCP/IP プロトコル

Light bulb  Note: FPC/Lazarus には、ネットワーキングの機能を使うための様々なライブラリ(Synapse, lnet, fphttpclient, Indy,...)があるため、それらのライブラリに対して、多くの例が記述できると思います。 したがって、you may see the same examples multiple times - for different libraries. Have a look at the [1] or [2] frameworks for examples on how to build frameworks that can use multiple network libraries

CGI/FastCGI - REST, CRUD, チャットやブログ、ウェブページなど

これらの機能は fcl-web を使うことで可能となります。 また、 Brook フレームワーク( this page )でも実装されています。

SSH/Telnet クライアント、メールの送信、ファイルのダウンロードや OAuth v1.0 の例

Synapseのページをご覧ください。

Webサーバの例

以下は Synapse ライブラリを用いて記述した http サーバの例です。Mac OS Xでテストしました。ただし、Mac OS Xの socket ユニットでは定数 MSG_NOSIGNAL が定義されていないため、Synapse のソースに定数定義 MSG_NOSIGNAL = $20000 を追加してコンパイルしました(訳注 : 2010年9月現在SVNで流れている Synapse の新バージョンでは、上記の定数が追加されており、無修正でコンパイルできます)。

{
  マイクロ Pascal ウェブサーバ
 
  Synapseライブラリを用いた極単純なウェブサーバの実装例である。
 
  ブロッキングモードのソケットを用いた単一スレッドアプリケーションであるため
  複数のリクエストを並行して処理することはできない。

  ブラウザから受け取ったヘッダは標準出力に出力される。

  サービス可能なウェブページのURIは固定で、'/' のみである。
  ほかのURIに対しては '504 not found' を返す。
}
program upserver;

{$ifdef fpc}
  {$mode delphi}
{$endif}

{$apptype console}

uses
  Classes, blcksock, sockets, Synautil, SysUtils;

{@@
  コネクションに参加する。ヘッダを読み、しかるべき返信を行う
}
procedure AttendConnection(ASocket: TTCPBlockSocket);
var
  timeout: integer;
  s: string;
  method, uri, protocol: string;
  OutputDataString: string;
  ResultCode: integer;
begin
  timeout := 120000;

  WriteLn('Received headers+document from browser:');

  //リクエストラインを読み込む
  s := ASocket.RecvString(timeout);
  WriteLn(s);
  method := fetch(s, ' ');
  uri := fetch(s, ' ');
  protocol := fetch(s, ' ');

  //リクエストヘッダを読み込む
  repeat
    s := ASocket.RecvString(Timeout);
    WriteLn(s);
  until s = '';

  // ここで出力ストリームに文書を書き込む

  if uri = '/' then
  begin
    // 出力する文書をストリームに書く
    OutputDataString :=
      '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
      + ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' + CRLF
      + '<html><h1>Teste</h1></html>' + CRLF;

    // ヘッダをクライアントに返信する
    ASocket.SendString('HTTP/1.0 200' + CRLF);
    ASocket.SendString('Content-type: Text/Html' + CRLF);
    ASocket.SendString('Content-length: ' + IntTostr(Length(OutputDataString)) + CRLF);
    ASocket.SendString('Connection: close' + CRLF);
    ASocket.SendString('Date: ' + Rfc822DateTime(now) + CRLF);
    ASocket.SendString('Server: Servidor do Felipe usando Synapse' + CRLF);
    ASocket.SendString('' + CRLF);

  //  if ASocket.lasterror <> 0 then HandleError;

    //文書をブラウザに送信する
    ASocket.SendString(OutputDataString);
  end
  else
    ASocket.SendString('HTTP/1.0 504' + CRLF);
end;

var
  ListenerSocket, ConnectionSocket: TTCPBlockSocket;
begin
  ListenerSocket := TTCPBlockSocket.Create;
  ConnectionSocket := TTCPBlockSocket.Create;

  ListenerSocket.CreateSocket;
  ListenerSocket.setLinger(true,10);
  ListenerSocket.bind('0.0.0.0','1500');
  ListenerSocket.listen;

  repeat
    if ListenerSocket.canread(1000) then
    begin
      ConnectionSocket.Socket := ListenerSocket.accept;
      WriteLn('Attending Connection. Error code (0=Success): ', ConnectionSocket.lasterror);
      AttendConnection(ConnectionSocket);
    end;
  until false;

  ListenerSocket.Free;
  ConnectionSocket.Free;
end.


TCP/IP Client - Server Example using built-in FCL-Net components

Please have a look at this blog post.

Download HTTP page body, web server upload using POST, get external IP address

These examples (using the FPC/Lazarus built in fphttpclient) can be found at fphttpclient#Examples

Webサービス

W3C によると、 Web サービスとは ネットワーク越しに機械と機械を相互に利用できるように設計されたソフトウェアの名称です。

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.

WEBサービスには、WSDLなど、「機械が処理可能」な形式で記述されているインタフェースがあります。 また、他のシステムは、多くの場合、インタフェースによってSOAPに内包されるメッセージを使用し定められた方法でウェブサービスと対話します。もしくは、RESTによる方法を取るかもしれません。 これらのメッセージは、通常HTTPを使用して伝達され、ウェブ関連の他の規格に関連するXMLから成りたっています。

様々なプログラミング言語で書かれ、様々なプラットホームで動くソフトウェアアプリケーションは、データをおたがいに一つのコンピュータでコミュニケーションを処理します。それと同様の方法を使って、インターネットのようなコンピュータネットワークの上でもコミュニケーションを行うために、WEBサービスを利用することができます。

この相互運用性(例えば、WindowsとLinuxアプリケーションの間など)はオープンスタンダードの運用によるものです。 OASISとW3Cはウェブサービスのアーキテクチャと標準化の策定に責任や権限がある主な委員会です。

ウェブサービス実装間の相互運用性を改良するため、WS-I委員会は、さらに定義する一連のプロフィールを規格の関連の開発をしています。

FPC & Lazarus のための Web サービスツールキット

Web Service Toolkit は FPC と Lazarus のための WEBサービス のパッケージです。

以下もご参照ください

  • Web Development Portal
  • Networking libraries - comparison of various networking libraries
  • Brook Framework - The perfect Free Pascal framework for your web applications. It's pure Pascal. You don't need to leave your preferred programming language.
  • FastPlaz - Fast Web Framework for pascal. More features like theme/templating, simple Model, session, mailer, etc.
  • Sockets - TCP/IP ソケットコンポーネント
  • fcl-net - Networking library supplied with FPC
  • lNet - 軽量ネットワークコンポーネント
  • Synapse - Serial port and synchronous TCP/IP Library
  • XML Tutorial/ja - XML はしばしばネットワーク通信で用いられます
  • FPC and Apache Modules
  • fcl-web - Also known as fpWeb, this is a library to develop web applications which can be deployed as cgi, fastcgi or apache modules.
  • セキュア・プログラミング
  • Internet Tools - A wrapper around Synapse/wininet/Android's httpcomponents simplifying https and redirections, and a XPath/XQuery/CSS Selector/JSONiq engine to process the downloaded pages