Networking/es: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Networking/es
| Old | New | Line | |
|---|---|---|---|
| 1 | + | # Trabajando en RED | |
| 2 | + | ||
| 3 | + | Esta página será el comienzo para las tutorias sobre la programación para red con Lazarus. No soy un experto en la programación para redes y agregaré al artículo todo lo queaprendo sobre esta cuestión. Invito a otros a que ayuden a crear artículos sobre trabajo en redes. Agregue un enlace en la sección siguiente, agregue una página y cree su propio artículo de WiKi. En esta página se dará información de carácter general . | |
| 4 | + | ||
| 5 | + | ## Otras tutorías sobre trabajo en redes | |
| 6 | + | ||
| 7 | + | - [[Secure programming|Programación segura]] | |
| 8 | + | - [[Sockets|Componentes sobre TCP/IP Sockets]] | |
| 9 | + | - [[lNet]] - Componentes ligeros para trabajo en red | |
| 10 | + | - [[XML Tutorial/es|Tutoría XML]] - XML se utiliza frecuentemente en comunicaciones en la red | |
| 11 | + | - [[FPC and Apache Modules|FPC y módulos Apache]] | |
| 12 | + | ||
| 13 | + | ## Protocolo TCP/IP | |
| 14 | + | ||
| 15 | + | ### Ejemplo de Servidor Web | |
| 16 | + | ||
| 17 | + | El código que sigue es un ejemplo de servidor http escrito con Synapse y probado en Mac OS X, después de cambiar los fuentes de Synapse para utilizar una constante fija \$20000 como MSG_NOSIGNAL, porque esta constante no estaba presente en la unidades 'Sockets' para Mac OS X. | |
| 18 | + | ||
| 19 | + | ``` pascal | |
| 20 | + | { | |
| 21 | + | The Micro Pascal WebServer | |
| 22 | + | ||
| 23 | + | This is a very simple example webserver implemented with the Synapse library. | |
| 24 | + | ||
| 25 | + | It works with blocking sockets and a single thread, so it | |
| 26 | + | can only handle one request at a given time. | |
| 27 | + | ||
| 28 | + | It will write the headers that it receives from the browser | |
| 29 | + | to the standard output. | |
| 30 | + | ||
| 31 | + | It serves a fixed webpage for the / URI | |
| 32 | + | For any other URI it will return 504 not found | |
| 33 | + | } | |
| 34 | + | program upserver; | |
| 35 | + | ||
| 36 | + | {$ifdef fpc} | |
| 37 | + | {$mode delphi} | |
| 38 | + | {$endif} | |
| 39 | + | ||
| 40 | + | {$apptype console} | |
| 41 | + | ||
| 42 | + | uses | |
| 43 | + | Classes, blcksock, sockets, Synautil, SysUtils; | |
| 44 | + | ||
| 45 | + | {@@ | |
| 46 | + | Attends a connection. Reads the headers and gives an | |
| 47 | + | appropriate response | |
| 48 | + | } | |
| 49 | + | procedure AttendConnection(ASocket: TTCPBlockSocket); | |
| 50 | + | var | |
| 51 | + | timeout: integer; | |
| 52 | + | s: string; | |
| 53 | + | method, uri, protocol: string; | |
| 54 | + | OutputDataString: string; | |
| 55 | + | ResultCode: integer; | |
| 56 | + | begin | |
| 57 | + | timeout := 120000; | |
| 58 | + | ||
| 59 | + | WriteLn('Received headers+document from browser:'); | |
| 60 | + | ||
| 61 | + | //read request line | |
| 62 | + | s := ASocket.RecvString(timeout); | |
| 63 | + | WriteLn(s); | |
| 64 | + | method := fetch(s, ' '); | |
| 65 | + | uri := fetch(s, ' '); | |
| 66 | + | protocol := fetch(s, ' '); | |
| 67 | + | ||
| 68 | + | //read request headers | |
| 69 | + | repeat | |
| 70 | + | s := ASocket.RecvString(Timeout); | |
| 71 | + | WriteLn(s); | |
| 72 | + | until s = ''; | |
| 73 | + | ||
| 74 | + | // Now write the document to the output stream | |
| 75 | + | ||
| 76 | + | if uri = '/' then | |
| 77 | + | begin | |
| 78 | + | // Write the output document to the stream | |
| 79 | + | OutputDataString := | |
| 80 | + | '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' | |
| 81 | + | + ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' + CRLF | |
| 82 | + | + '<html><h1>Teste</h1></html>' + CRLF; | |
| 83 | + | ||
| 84 | + | // Write the headers back to the client | |
| 85 | + | ASocket.SendString('HTTP/1.0 200' + CRLF); | |
| 86 | + | ASocket.SendString('Content-type: Text/Html' + CRLF); | |
| 87 | + | ASocket.SendString('Content-length: ' + IntTostr(Length(OutputDataString)) + CRLF); | |
| 88 | + | ASocket.SendString('Connection: close' + CRLF); | |
| 89 | + | ASocket.SendString('Date: ' + Rfc822DateTime(now) + CRLF); | |
| 90 | + | ASocket.SendString('Server: Servidor do Felipe usando Synapse' + CRLF); | |
| 91 | + | ASocket.SendString('' + CRLF); | |
| 92 | + | ||
| 93 | + | // if ASocket.lasterror <> 0 then HandleError; | |
| 94 | + | ||
| 95 | + | // Write the document back to the browser | |
| 96 | + | ASocket.SendString(OutputDataString); | |
| 97 | + | end | |
| 98 | + | else | |
| 99 | + | ASocket.SendString('HTTP/1.0 504' + CRLF); | |
| 100 | + | end; | |
| 101 | + | ||
| 102 | + | var | |
| 103 | + | ListenerSocket, ConnectionSocket: TTCPBlockSocket; | |
| 104 | + | begin | |
| 105 | + | ListenerSocket := TTCPBlockSocket.Create; | |
| 106 | + | ConnectionSocket := TTCPBlockSocket.Create; | |
| 107 | + | ||
| 108 | + | ListenerSocket.CreateSocket; | |
| 109 | + | ListenerSocket.setLinger(true,10); | |
| 110 | + | ListenerSocket.bind('0.0.0.0','1500'); | |
| 111 | + | ListenerSocket.listen; | |
| 112 | + | ||
| 113 | + | repeat | |
| 114 | + | if ListenerSocket.canread(1000) then | |
| 115 | + | begin | |
| 116 | + | ConnectionSocket.Socket := ListenerSocket.accept; | |
| 117 | + | WriteLn('Attending Connection. Error code (0=Success): ', ConnectionSocket.lasterror); | |
| 118 | + | AttendConnection(ConnectionSocket); | |
| 119 | + | end; | |
| 120 | + | until false; | |
| 121 | + | ||
| 122 | + | ListenerSocket.Free; | |
| 123 | + | ConnectionSocket.Free; | |
| 124 | + | end. | |
| 125 | + | ``` | |
| 126 | + | ||
| 127 | + | ## Servicos *web* (*WebServices*) | |
| 128 | + | ||
| 129 | + | Según el [W3C](http://www.w3.org/) un **servicio *web*** es un sistema software diseñado para dar soporte a la operación interactiva entre máquinas a través de una red. Cuenta con un interfaz que está descrito en un formato procesable por una máquina que es WSDL. Otros sistemas interactuan con el servicio *web* de la forma descrita en la interfaz utilizando mensajes, que irán dentro de *sobres* [SOAP](http://es.wikipedia.org/wiki/SOAP), o siguiendo un acercamiento [REST](http://es.wikipedia.org/wiki/Representational_State_Transfer). Los mensajes se transportan típicamente usando HTTP, y se componen normalmente de XML junto con otros estándares *web* relacionados. Aplicaciones informáticas escritas en distintos lenguajes de programación y funcionando en plataformas diversas pueden utilizar servicios *web* para intercambiar datos sobre las redes de ordenadores, como Internet ,de una forma similar a la comunicación entre procesos sobre un único ordenador. Esta interoperabilidad (v.g., entre aplicaciones Windows y Linux) es posible debido al uso de estándares abiertos. [OASIS](http://es.wikipedia.org/wiki/OASIS_(organización)) y [W3C](http://www.w3.org/) son los comités más importantes responsables de la arquitectura y de la estandardización de los servicios de red. Para mejorar la interoperabilidad entre las implementaciones de servicios de red, la organización [WS-I](http://es.wikipedia.org/wiki/WS-I) está desarrollando una serie de perfiles para definir mejor los estándares implicados. | |
| 130 | + | ||
| 131 | + | ### Web Service Toolkit for FPC & Lazarus | |
| 132 | + | ||
| 133 | + | [[Web Service Toolkit]] es un paquete de herramientas para servicios *web* para FPC y Lazarus. | |
| 134 | + | ||
| 135 | + | ### Ver también | |
| 136 | + | ||
| 137 | + | [[XML Tutorial/es]] | |
| 138 | + | ||
| 139 | + | ## External Links | |
| 140 | + | ||
| 141 | + | --- | |
| 142 | + | *From the Free Pascal wiki, page "Networking/es", as it stood on 2022-01-22 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 143 | + | Category: Castellano | |
| 144 | + | Category: Español |
