.


:




:

































 

 

 

 


TELNET-

 

: Telnet-, .

 

1.

 

Telnet- Id Telnet IndyClients .

Telnet- :

Terminal - ;

Host - IP- ;

Port - ;

Connected - . Telnet- :

Connect - ;

Disconnect - ;

SendCh - . Idtelnet ;

OnConnected - ;

OnDataAvailable - ;

OnStatus .

 

2.

 

2.1. Telnet-

 

Telnet- , . 1, .

 

. 1

 

1) , .

 

1

,

IdTelnet1 TIdTelnet   telnet-. IdClients
StatusBarl TSlatusBar . Win32
Panel1 TPanel ,
Memo1 TMemo . , ,
Label1 TLabel
Label2 TLabel
Labe3 TLabel
Edit1 TEdit IP-
SpinEdit1 TSpinEdit   . Samples
ComboBoxl TComboBox
Buttonl TButton Connect
Button2 TButton Disconnect

 

2) Editl () Text IP- . - 127.0.0.1.

3) SpinEdit1 () Value . 21 (FTP -).

4) ComboBox 1 () Text - VT100, Items - , . 2.

 

. 2

 

5) OnCiick Conned :

 

procedure TTelnetForm.Button1Click(Sender: TObject);

begin

IdTelnetl.Terminal:= ComboBox1.Text;

IdTelnetl.Host:= Edit1.Text;

IdTelnetl.port:= SpinEditl.Value;

IdTelnetl.Connect;

end;

 

IdTelnet1 , , .

6) OnCiick Disconnect :

 

procedureTTelnetForm.Button2Click(Sender: (Object);

begin

If IdTelnet1.Connected then IdTelnetl.Disconnect;

end;

 

Disconnect IdTelnetl, .

7) Memo1 OnKeyPress. :

 

procedure TTelnetForm.Memo1KeyPress(Sender: TObject: var Key: Char);

begin

if IdTelnetl.Connected then

begin

IdTelnetl.SendCh(Key);

end;

end;

 

: IdTelnetl , . SendCh IdTelnetl, . Memol .

8) OnConnected IdTelnetl :

 

procedure TTelnetForm.IdTelnetlConnected(Sender: TObject);

begin

Memol.Lines.Add(' ');

Memol.Lines.Add(' ');

Memol.Lines.Add();

end;

 

, , .

9) OnDataAvailable IdTelnetl :

 

procedure TTelnetForm.Id'T'elnet1 DataAvailable(Sender: TldTelnet;

const Buffer: String);

const

//

CR=#13;

LF=#10;

var

Start, Stop: Integer;

Begin

Memol.Lines. Add(");

Start:= 1;

//

Stop:= Pos(CR, Buffer);

// , Memo1

//

if Stop = 0 then

Stop:= Length(Buffer) + 1;

// ,

while Start <= Length(Buffer) do

begin

// Memo1

Memo1.Lines.Strings[Memo1.Lines.Count-1]:=

Memo1.Lines.Strings[Memo1.Lines.Count - l]+Copy(Buffer, Start, Stop -

Start);

if Buffer[Stop]=CR then

begin

Memol.Lines.Add(");

end;

Start:= Stop + 1;

//

if Start>Length(Buffer) then

Break;

If Buffert[Start]=LF then

Start:=Start + 1;

Stop:= Start;

while (Buffer[Stop]<>CR) and (Stop<= Length(Buffer)) do

Stop:=Stop + 1;

end;

end;

 

, .

Memol. , , . CR LF #13 #10, .

10) OnStatus IdTelnet1 :

 

procedure TTelnetForm.IdTelnetl Status(axSender: TObject; const axStatus: TIdStatus: const asStatusText: Siring); begin

if axStatus =hsDisconnected then

Memo1.Lines.dd( ');

end;

 

11) OnCloseQuery :

 

procedure TTelnetForm.FormCloseQuery(Sender: TObject;

var CanClose: Boolean);

begin

if ldTelnetl.Connected then

IdTelnetl.Disconnect;

end;

 

- , , .

 

2.2. Telnet-

 

1) Telnet- Echo ( 7). , , .

2) telnet- ( 13). .

3) telnet- c FTP ( 21). , :

User anonymous;

Pass;

Help;

List;

. .;

Quit.

FTP-c.

4) telnet- SMTP ( 25). , :

Echo;

. .

Quit.

 

 

1. . Delphi /. . ., , 2003. 640 .

2. . . Delphi . ., -, 2004. 368 .

 

 

1. Telnet-.

2. IdTelnet ?

3. IdTelnet?

4. IdTelnet , ?


21

CGI-

 

: CGI- Delphi, , Web- .

 

1.

 

.

CGI-.

FORM.

FORM.

CGI- .

 

1.1. CGI-

 

Common Gateway Interface - Web- . CGI - . , CGI, CGI- (CGI-).

, WWW-, . CGI Web- , . CGI- Web-, .

CGI- . 1.

 

 

 


. 1. CGI-

 

CGI- .

1) CGI- Web-.

2) HTML-, FORM.

3) FORM Web-.

4) Web- CGI-, .

5) CGI- HTML-, Web-.

6) Web- .

CGI -. , METHOD. GET, , . ( , .), ( QUERY_STRING). POST . (CONTENT_TYPE CONTENT_LENGTH).

CGI- . . - , TT-, HTTP.

 

1.2. FORM

 

FORM HTML-. , FORM . FORM :

<FORM ACTION="url" METHOD ="POST>...</FORM>.

:

ACTION - URL , . , URL . CGI-.

METHOD - , . , . POST.

:

GET - , URL, ;

POST - URL, ;

ENCTYPE - . POST ( ) - application/x-www-form-urlencoded.

FORM , , FORM. , FORM INPUT, SELECT TEXTAREA.

 

1.2.1. INPUT

 

INPUT FORM. , , .

INPUT .

TYPE :

hidden - , . ;

image - , , . ( );

text - , ;

password - ; ;

checkbox - , on () off ();

radio - , on off; NAME ;

submit - , ;

reset - , .

NAME - ( ) . submit

reset, . . .

VALUE - , . checkbox radio VALUE , ( ); checkbox radio - on. submit reset VALUE .

CHECKED - . , checkbox radio . checkbox radio.

SIZE - ; .

MAXLENGTH - , , ( ). - . , .

 

1.2.2. SELECT

 

<FORM >... </FORM> SELECT, HTML- ( INPUT TEXTAREA) ( FORM). SELECT .

INPUT, SELECT . SELECT OPTION, ( HTML-), :

 

<SELECT NAME="a-menu">

<OPTION> First option.

<OPTION> Second option.

</SELECT>.

 

SELECT :

NAME - SELECT-. , . . ( INPUT).

SIZE - SIZE 1 , SELECT Motif. SIZE=2 , SELECT ; SIZE , .

MULTIPLE - , , SELECT . MULTIPLE SELECT , SIZE.

OPTION SELECTED, , . SELECT ( MULTIPLE), .

 

1.2.3. TEXTAREA

 

TEXTAREA . TEXTAREA :

NAME - ;

ROWS - ();

COLS - ().

TEXTAREA , . TEXTAREA . TEXTAREA :

 

<TEXTAREA NAME-"foo" ROWS=4 COLS=40>

</RE>

TEXTAREA :

<TEXTAREA NAME=foo" ROWS=4 COLS=40>

Default contents go here.

</TRE>.

 

ASCII-. ( Default contents go here ).

 

13. CGI-

 

GET

submit, URL : action?name=value&name=value&name=value, action - URL, ACTION FORM, URL , ACTION .

, . , value , name=.

checkbox radio value VALUE , . . checkbox NAME ( VALUE), . radio , NAME VALUE.

 

POST

GET, URL, ACTION , POST. ACTION, URL, , , .

 

1.4. CGI-

 

CGI- .

SERVER_SOFTWARE - , ( ). : /.

SERVER_NAME - , ; DNS- IP- , URL.

GATEWAY_INTERFACE - CGI- , . : CGI/.

Web- CGI-:

SERVER_PROTOCOL - , . : /;

SERVER_PORT - , ;

REQUEST_METHOD - , . HTTP - GET, HEAD, POST ..;

PATH_INFO - , . , , . PATH_INFO;

PATH_TRANSLATED - PATH_INFO, , ;

SCRIPT_NAME - CGI-, ( URL);

QUERY_STRING - , ? URL, CGI-. . . ;

REMOTE_HOST - , . , REMOTE_ADDR, :

REMOTE_ADDR - IP- , ;

AUTH_TYPE - , ;

REMOTE_USER - , , ;

REMOTE_IDENT - HTTP- RFC 931, , ;

CONTENT_TYPE - , , , HTTP POST PUT, ;

CONTENT_LENGTH - , .

 

2.

 

2.1.

 

. .

1) Delphi File / New, Console Application .

. Console Application, Application, Delphi View / Units . , :

 

program Project 1;

{@APPTYPE CONSOLE}

uses

SysUtils:

Begin

// CGI-

end.

 

2) CGI- ( ):

 

//

Writeln('Content-Type:text/html');

// ,

Writeln;

Writeln('<HTML>');

Writeln('<HEAD>');

Writeln('<TITLE-> GI--</TITL>');

Writeln(</HEAD>');

Writeln('<BODY>');

Wrileln('<H2 ALIGN=CENTER> Hello, World! </H2>');

Writeln('</BODY>');

Writeln('</HTML');.

 

3) Web-, .

4) HTML-, CGI-. - , FORM ( HREF=...). HTML-:

 

<HTML>

<HEAD>

<TITLE> GI-</IL>

</HEAD>

<BODY>

<2> Form. GET </2>

<FORM METHOD="GET" ACT1ON=http://myself/temp/hello.exe>

<INPUT TYPE="SUBMIT">

</FORM>

<HR>

<BR>

<A HREF="http://myself/temp/hello.exe">

"A HREF"

</>

</BODY>

</HTML>.

 

5) HTML- Internet Explorer (IE). IE , (. 2). IE , CGI- (. 3).

 

. 2

 

. 3

 

 

2.2. CGI- , ,

 

, .

1) :

 

program param;

{@APPTYPE CONSOLE}

uses

SysUtils,

Windows;

Var

buff: PChar;

ContentLength, i: Integer;

St1,St2: String;

C: Char;

Begin

//

GetMem(buff,50);

//

GetEnvironmentVariable('REQUEST_METHOD', buff, 50):

// PChar

St1:= StrPas(buff);

//

Freemem(buff);

i:=length(St1);

While i>0 do

begin

St1[i]:=Upcase(St1[i]);

dec(i);

end;

If St1='GET then

begin

GetMem(buff, 200);

GetEnvironmentVariable(QUERY_STRING', buff 200);

St2:=StrPas(buff);

Freemem(buff);

end;

If St1=POST then

begin

GetMem(buff, 50);

GetEnvironmentVariable('CONTENT_LENGTH', buff 50);

St2:= StrPas(buff);

Freemem(buff);

ContentLength:= StrToInt(St2);

St2:=";

For i:=1 to ContentLength do

begin

Read(C);

St2:= St2+C;

end;

end;

St1:='Method'+St1;

St1:= '<H2 ALIGN=CENTER>'+St1+</H2>';

Writeln('Content-Type: text/html');

Writeln;

Writeln('<HTML>');

Writeln('<HEAD>');

Writeln('<TITLE> CGI- </IL>');

Writeln(<</HEAD>');

Writeln('<BODY>');

Writeln('<H2 ALIGN=CENTER>METHOD+St1+'</H2>');

Writeln('<BR>');

Writeln('<H2 ALIGN=CENTER>PARAMETRS:'+St2+'</H2>');

Writeln('</BODY>');

Writeln(</HTML>');

end.

 

2) Web-, .

3) HTML-:

 

<HTML>

<HEAD>

<TITLE> GI-</1L>

</HEAD>

<BODY>

<2> GET </H2>

<FORM METHOD="GET"

ACTION= http://myself/temp/param.exe >

<INPUT TYPE="TEXT" NAME="Edit1" VALUE="test">

<BR><BR>

<INPUT TYPE="SUBMIT">

</FORM>

<HR>

<BR> <BR>

<H2> POST </H2>

<FORM METHOD="POST

ACTION="http://myself/temp/param.exe">

<INPUT TYPE="TEXT" NAME="Edit1" VALUE="test">

<BR><BR>

<INPUT TYPE="SUBMIT">

</FORM>

<BODY>

<HTML>.

 

4) HTML- IE. IE , . 4. GET

, . 5, POST , . 6.

 

. 4 . 5

 

. 6

 

5) , CGI- , . 1,

 

1

REQUEST_METHOD (GET POST)
SERVER_NAME I-
SERVER_PORT ,
SERVER_PROTOCOL ,
PATH_INFO ,
REMOTE_ADDR IP- ,
REMOTE_HOST ,

 

2.3. CGI-,

 

1) HTML-, , , , 2x2. SUBMIT CGI-.

2) CGI- .

 

 

1. . ., . . Web- Delphi. ., XB-, 2003.672 .

2. . Delphi /. . ., , 2003. 640 .

3. . . . ., , 2002.688 .

 

 

1. FORM.

2. GET POST?

3. CGI-.

4. CGI-?


22

WEB-

 

: Delphi Web-.

 

.

TWEBMODULE.

REQUEST.

RESPONSE.

TWEBMODULE.

 

1.

 

1.1. TWEBMODULE

 

TWebModule Web-, Delphi. HTTP-.

TWebModule - Action, , , .

TWebActionItem .

PathInfo: String - , ( , ) .

MethodType: TMethodType - , , , . : mtGet, mtPost, mtHead, mtPut, mtAny.

Default: Boolean - . true, , .

Enabled: Boolean - , (true) (false) T- PathInfo MethodType, .

Producer: TCustomContentProducer - , web-. .

Actions OnActions. OnActions :

 

procedure TWebModule1.WebModule1 WebActionItem1 Action (Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);.

 

Request , . Response . Handled , , . false.

 

1.2. REQUEST

 

Request TWebRequest - Web-. :

Property Content: String - , POST. HTTP-, ;

Property ContentFields: TStrings - , POST. ontentFields , , FORM, , ;

Property Query: String - , GET;

Property QueryFields: TStrings - . GET;

Property RemoteAddr: String - IP- , ;

Property RemoteHost: String , ;

Property Method: String ,

.

 

1.3. RESPONSE

 

Response TWeb Response - , HTTP-. :

Property ContentType: String , ;

Property ContentLength: Integer , ;

Properly Content: String - ;

Property ContentStream: TStream - TStream, . .

 

1.4. TWEBMODULE

 

, Actions, TWebModule. : AfterDispatch, BeforeDispatch, OnCreate OnDestroy.

:

AfterDispatch: THTTPMethodEvent - , HTTP- ( OnActions - Actions), ;

BeforeDispatch: THTTPMethodEvent - , HTTP- - . HTTP-;

OnCreate: TNotifyEvent - TWebModule. , , . , , ;

OnDestroy: TNotifyEvent - TWebModule. , . , , .

 

2.

 

2.1. WEB- Delphi -WEBMODULE

 

Web-, . :

- ;

- HTML.

.

 

1: Web -.

1) Delphi File / New, Web Server Application .

2) . CGI Stand-alone executable. CGI-, TWebModule.

2: , .

1) TWebModule Action . (. 1).

2) . ( Add New), Add , .

 

. 1

 

3) . (. 1) . PahtInfo /1. , HTTP- , CGI- /1, : http://nts/tmp/mult.exe/l. .

4) . Events OnAction. :

 

procedure TWebModule1.WebModule1 WebAclionItem1 Action(Sender: TObject;

Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);

VAR

Num1, num2, result: integer;

begin

num1: StrToInt(Request.ContentFields.Values[num1']);

num2: StrToInt(Request.ContentFields.Values['num2']);

result:= num1*num2;

If Request.ContentFields.Values['resuIt']=IntToStr(result)

then Response.Content:=

'<b> !!! </b><p> !'

else Response.Content:=

' <>'+

'<a href="http://myself/temp/mult.exe">'+

'<> </></>';

Handled:= True;

end;.

 

5) . PathInfo , Default True. , . OnAction :

 

procedure TWebModule1.WebModule1 WebActionItem2Action(Sender:

TObject;

Request: TWebRequest; Response: TWebResponse: var Handled: Boolean);

Var

num1, num2: Word;

begin

Randomize;

Num1:= Random(8)+l;

num2:=Random(8)+1;

Response.Content:='<html><head> <Title> '+

'</title></head><body>'+

<h1 > </h1>';

Response.Content:= Response.Content+

' , ,+

' ""';

Response.Content:= Response.Content+

<form method="POST +

'action="http://myself/temp/mult.exe/1 "<table>'+

'<table> <tr><td> <input type="text" name="num1" size=" 1"'+

!value='+IntToStr(num1)+ '></td><td> x'+

'<td> <input type="text" name="num2" size="1" value='+

IntToStr(num2)+'></td><td>='+

'<td> <input type="text" name="result" size="3"> </td>'+

'<td> <input type=submit" name="post" value="">'+

'</td></tr><table></form>'+

<form method="POST"+

'action="http://myself/temp/mult.exe">'+

'<p><input type="submit" value=" " +

'name="New"></p></form></body></html>';

Handled:=True;

end;.

 

6) ( ) HTML-, . 2.

7) . , HTML-, . 3, - , HTML-c, . 4.

 

3:

 

1) Web-, .

2) Internet Explorer URL : http://nts/tmp/mult.exe. , , .

 

TWebModule . File / Open *.pas.

. 2

 

. 3

. 4

 

 

 

1. . ., . . Web- Delphi. ., -, 2003. 672 .

2. . Delphi /. . ., , 2003. 640 .

3. . . . . , 2002. 688 .

 

 

1. TWebModule.

2. TWebModule?

3. TWebModule?

4. ?



<== | ==>
TFTP |
:


: 2018-11-11; !; : 671 |


:

:

: , .
==> ...

1649 - | 1616 -


© 2015-2024 lektsii.org - -

: 0.509 .