    262	  

     11.    Internet 

    Visual Basic     -,  
    Internet.     
    Web,   Web-,  
       ,  
    . 
         -,  
  .   ,     
 Personal Web-Server,      
 -. 

    11.1.   

     (socket)     (),  
       . , 
     . 
           , , 
 ,      . 
           TCP/IP  
Internet.         
 Winsock. 

    11.1.1.   

         : 
       ,     (  IP); 
        ,          
   ; 
         (stream  datagram   TCP  UDP). 
         stream  datagram    
.  stream (),  TCP,  ,   
.    ,  ,    
 ,    . 
      datagram,  UDP,     .  
 ,   ,  , --,  
     . 
              
  ,       
,    . 

    11.1.2.   

           : 
       -,      
   ; 
       -,       
   ; 
          . 


     11.    Internet 263 


    11.1.3.   Winsock 

      Winsock,   ,  
     TCP  UDP.    
  Microsoft Access, Visual Basic, Visual  ++  Visual 
FoxPro.      /,   
   TCP    Winsock API  
.        Winsock, 
           . 

    . 11.1.   Winsock  . 


      

          
. ,         
 : 
    1.           
     ?  ,     
TCP,     . 
    2.       (,  
   )?     TCP 
     .   , 
,          . 
    3.          ? 
,          
 , , ,    UDP. 
 UDP       . 

        TCP 

     TCP (Transfer Control Protocol)    
    .   ,  
     .   
-,    -   IP 
( RemoteHost),    ( RemotePort),    
"".    Connect. 
      -,    
( Local-Port)    Listen.  - 
 ,   ConnectionRequest.   
    ConnectionRequest   Accept. 
        ,     
   .   ,   
SendData.    


    264	  

    DataArrival.     
   DataArrival   GetData. 

        UDP 

    UDP (User Datagram Protocol)    .    
 TCP    .  ,  
UDP    ,   . 
      ,     LocalPort 
-.  -      
RemoteHost  Internet -,    RemotePort    
,     LocalPort -,    SendData, 
   .  -   
    GetData    DataArrival. 
       Winsock   
       Winsock     ,   
      Components: 
    1.   Project  Components. 
    2.   Controls  Microsoft Winsock Control 5.0   . 

    11.1.4.      Winsock 

      ,   ,    
      Winsock,   ,  
      . 
          Winsock 
   : 
    1.   Protocol,  ,   
     . 
    2.   LocalPort,  ,   
    . 
    3.   Listen,     
   . 
    4.   ConnectionRequest,    
    . 
         . ,   
"  Winsock". 
           
Winsock     : 
    1.   RemoteHost,    ,  
    . 
    2.   RemotePort,    , 
       . 
    3.   Connect,      
 . 
         .   
"  Winsock". 


     11.    Internet	265 

              
 .      : 
    1.   SendData         
 . 
    2.   GetData    DataArrival    
      . 
            .  
 "   ". 

        

             
     ,    
     . 
       -: 
    1.   RemoteHost,    ,  
  -   . 
    2.   RemotePort,     
,    -      . 
    3.   Bind,      , 
   Internet Protocol (IP). 
       -   : 
    1.   RemoteHost,    ,  
    -. 
    2.   RemotePort,     
,    -      . 
    3.  Bind      ,  
  IP. 

    11.1.5.   Winsock 

      -    Winsock  
         
.     ,      
 . 

      Protocol 

       Winsock     . 
           
 Protocol.        TCP. 

      Local Port    Listen 

          LocalPort  
      Listen.      
 Form_Load,     : 

    Private  Form_Load() 
    tcpServer.LocalPort = 1001 
    tcpServer.Listen End Sub 


     11.    Internet	265 

              
 .      : 
    1.   SendData         
 . 
    2.   GetData    DataArrival    
      . 
            .  
 "   ". 

        

             
     ,    
     . 
       -: 
    1.   RemoteHost,    ,  
  -   . 
    2.   RemotePort,     
,    -      . 
    3.   Bind,      , 
   Internet Protocol (IP). 
       -   : 
    1.   RemoteHost,    ,  
    -. 
    2.   RemotePort,     
,    -      . 
    3.  Bind      ,  
  IP. 

    11.1.5.   Winsock 

      -    Winsock  
         
.     ,      
 . 

      Protocol 

       Winsock     . 
           
 Protocol.        TCP. 

      Local Port    Listen 

          LocalPort  
      Listen.      
 Form_Load,     : 

    Private  Form_Load() 
    tcpServer.LocalPort = 1001 
    tcpServer.Listen End Sub 


     11.    Internet	267 

      

              
  GetData   Winsock,    
, -  . 

      GetData: o6bem.GetData , [,] [_] 

        Variant, ,   ,  
 ,     .  
_    ,      
 . 
            DataArrival: 

    Private  Sub Winsockl_DataArrival   (ByVal  bytesTotal  As  Long) 
    Dim  strData  As   String 
    Winsockl.GetData   strData,   vbString 
    '                 
    txtDisplay  =  txtDisplay   &   strData End  Sub 

     bytesTotal   DataArrival   
 . 

    11.2.   FTP  HTTP  Internet 

       (FTP  File Transfer Protocol)   
  (HTTP  Hypertext Transfer Protocol)    
   Internet . FTP    
    Internet   ,     
 . , HTTP   , 
        HTML. 
           Internet 
Transfer    -  FTP  HTTP.  
 ,      . 

    11.2.1.   Internet Transfer 

     Visual Basic   FTP  HTTP   
   Internet Transfer.    
    ,      
,   ,   OpenURL  Execute. 
         ,  Microsoft 
Internet Information Server  Personal Web-Server. 
       Internet Transfer     , 
        Components (. 11.2). 

    11.2.2.      Internet Transfer 

       ,      
Internet Transfer,       FTP  HTTP. 

    :  FTP  HTTP    .  
    21      FTP   
    .  80     
   HTTP. 


    268   FTP  HTTP  Internet 


    Jl 
    J 

    . 11.2.   Internet Transfer  . 


     OpenilRL  Execute 

          -    
OpenURL,   Execute. 
     OpenURL   ,     , 
 ,   FTP  HTTP.  
       .  OpenURL  
   ,   Execute. 
     Execute      .  
      StateChanged  
 Internet Transfer.  Execute    
    , ,  , , 
     .  Execute   
 HTTP,  GET, HEAD, POST  PUT,      
FTP,  GET, PUT, SEND  DELETE.  Execute   
 ,  OpenURL,     . 
          : 
    1.   AccessType,     . 
    2.   Execute,   . 
    3.   StateChanged,   StateChanged 
    . 
    4.  ,   ResponseCode  Responselnfo. 
    5.  GetChunk      . 
    6.   StillExecuting,   . 
    7.   Cancel,   ,   
     . 
         ,     
,    .      
      ,    . 
    ,     ,  
       .   
     .   
"  ". 


     11.    Internet 269 

          
  : 
    1.   AccessType,    . 
    2.   OpenURL,   . 
          
  .   "  ". 

    11.2.3.    


      AccessType 

     ,        
    (proxy) ,   
  AccessType   Internet Transfer.  
   ,    AccessType, 
  icUseDefault.    Internet    
    . 

    Inetl.Accesstype   =   icUseDefault 


      Execute 

           Execute  
 .   Execute: 

    .Execute url, , ,    
   HTTP: 

     

     

     

     ,      Internet Transfer. 

    url 

    . ,  URL,     
Internet Transfer  .  URL  ,  
   URL  . 
     

    . ,   ()   
(  . ). 
     

    . ,     (. ). 
     

    . ,   , 
   .   _: _ vbCrLf. 
         FTP: 

    	 

    GET	   URL,   URL. 
    HEAD	  . 
    POST	   .    . 
         GET, 
       . 
    PUT	 .       . 


    270   FTP  HTTP  Internet 


    :   FTP   ,  
URL,          .  
,  ""  ""   .  
  .  ,    FTP 
: _ 1 2. 

    ,      Execute   URL 
   : 

    Inetl.Execute   "FTP://ftp.microsoft.com",   _ "GET   Filel.txt   C:\Temp\File2.txt" 

    	 

    CD filel	  ,   filel. 

    COUP	    .  "CD.." 

    CLOSE	   FTP. 

    DELETE filel	  filel. 

    DIR filel	 filel (  ,    
  ).   filel  ,   
  .      
 GetChunk. 

    GET filel file2	  filel      /7/2. 

    LS filel	  filel (  ,   
   ).     
  GetChunk. 

    MKDIR/7/e?	  filel.      
   . 

    PUT filel file2	   filel   , 
  file2. 

    PWD	   .     
  GetChunk. 

    QUIT	  . 

    RECV filel file2	   filel     
 /72.  GET. 

    RENAME filel file2	  filel  2.    
     . 

    RMDIR filel	  filel.      
   . 

    SEND filel file2	   filel   , 
  file2.  PUT. 

    SIZE filel	   filel. 

         Execute    
    FTP: 

    Inetl.Execute "ftp://ftp.microsoft.com", "DIR" 


      StateChanged 

             
       StateChanged. 


     11.    Internet	271 

        ,    
icResponseComp-leted   StateChanged.     
  GetChunk. 
          icResponseCompleted 
  Select Case: 

    Private   Sub   Inetl_StateChanged(ByVal   State   as   Integer) Select   Case 
    Case  icResponseCompleted '           GetChunk Case 
 icError 
    Inetl.Cancel 
    '               
    '      End  Select End  Sub 

      GetChunk 

       icResponseCompleted  GetChunk  
       -.  
       icResponseCompleted  
Case,     : 

    Case   icResponseCompleted Dim  s  As   String '       
 s   =   Inetl.GetChunk(1024) Do  While   Len (s)    >   0 
    txtOutput  =   txtOutput   &   s 
    s   =   Inetl.GetChunk(1024) Loop 


     StillExecuting 

    ,    StillExecuting    
  Internet Transfer.     
,     Internet,    True 
       . 
          DoEvents   
  ,          
  : 

    Inetl.Execute   ...   '      -         Execute 
While  Inetl.StillExecuting 
    DoEvents Wend '       


       

          ,   
     .     
 . ,       
-     < Esc >.     
       Cancel  
 Internet Transfer. 


    272	  FTP  HTTP  Internet 

            
   Click  : 

    Private   Sub   cmdCancel_Click() 
    If   Inetl.StillExecuting  Then INetl.Cancel 
    End   If End  Sub 


    11.2.4.    

            
  OpenURL. 

      OpenURL: -m.OpenURL strURL[, _] 

     strURL    URL FTP  HTTP.   
 ,   .    ,  
  . 
     _       
(icString)   (icByteArray). 
        OpenURL      
   Internet   Microsoft FTP: 

    Dim  s  As   String 
    s   =   Inetl.OpenURL("ftp://ftp.microsoft. com",   icString) 
    txtListing.Text   =   s 

        AccessType .   
"  ". 

    11.2.5.    WebBrowser 

      WebBrowser      
   HTML     ActiveX. 
      WebBrowser  in-process  .   
    ,      
 .   WebBrowser    
 - ,     . 
      WebBrowser  -  
 ,   .    
  World Wide Web        . 
      WebBrowser    
    URL.     
,         
   ,   . 
      WebBrowser      
HTML.       ActiveX    
  ActiveX. 
       WebBrowser      
   , ,   
 Microsoft Excel   Microsoft Word. 


     11.    Internet	273 

    11.2.6.    WebBrowser 
          WebBrowser: 
            HTML  World Wide Web 
  ; 
         ,     
    ActiveX; 
          Web. 

       WebBrowser   Visual Basic 

       WebBrowser     ,   
     Components.       
Microsoft Internet Controls. 

    :          
   ,     
.   WebBrowser   
  . 


    11.2.7.    WebBrowser 

      ,      
WebBrowser,        Web. 
      : 
    1.   Navigate     .  
     URL. 
    2.     WebBrowser   
    NavigateComplete      
  URL ,   LocationURL  LocationName. 
    3.   GoBack, GoForward, GoSearch  GoHome  
,     ,    
History (). 
    4.   Busy, ,     
WebBrowser           
.    Stop       
  . 
    5.    Refresh  Refresh2   
 ,    . 
    6.     Web-,   
DownloadBegin, ProgressChange  DownloadComplete,     
    . 

    11.2.8.    WebBrowser 

           Web   
    Web-  . 
          .  
    Form_Load    Navigate. 
           Navigate  
  URL: 

    Private   Form_Load() 
    WebBrowser.Navigate _ 
    URL:="http://directoryl/pagel.htm" End Sub 
    ' . 136 


    274	  FTP  HTTP  Internet 

         URL   ,    . 
     NavigationComplete. 
       URL       ,   
      : 

    Private  Sub  wb_NavigateComplete(ByVal  URL As   String) 
    cboURL  =  WebBrowserl.LocationURL 
    sbMain.Panels(2)   =  WebBrowserl.LocationName End  Sub 


       

            , ,   
.       .   
          Click  
   ,    . 
        GoBack    Click  : 

    Private   Sub   cmdGoBack_Click() 
    WebBrowserl.GoBack End  Sub 


      

         Busy   Stop. 
        ,     
   If...Then      
WebBrowser   ,   : 

    Private   Sub   cmdStop_Click() If  WebBrowserl.Busy  Then 
WebBrowserl.Stop WebBrowserl.GoBack End   If End  Sub 


      

      ,    ,  
  Refresh   Refresh2. 
     Refresh  ,       
,      .  Refresh2  
,   ,   .  
  Refresh2        
,     . 
         Refresh    
,      : 

    Private   cmdRefresh_Click() 
    WbBrowserl.Refresh End  Sub 


       

          , ,  
 DownloadBegin, ProgressChange  DownLoadComplete,   
    . 


     11.    Internet	275 

           
DownloadBegin (   ProgressBar  StatusBar): 

    Private  Sub WebBrowserl__DownloadBegin () 
    '      ProgressBar 
    pbMain.Move   sbMain.Panels(1).Left,    10,   _ 
    sbMain.Panels(1).Width,   sbMain.Height   -   10 
    pbMain.Value   =   0 
    pbMain.Min   =   0 
    pbMain.Max  =   100 
    pbMain.Visible   =  True End  Sub 

       ProgressChange       
  . : 

    Private   Sub  wb_ProgressChange(ByVal   Progress  As   Long,   _ 
    ByVal   ProgressMax  As   Long) '         ProgressBar If  
 Progress   <>   -1   And  ProgressMax   <>   0   Then 
    pbMain.Value  =  Progress   *   100   /   ProgressMax End   If End  Sub 

      DownloadComplete,     
 .        
   Visible  False : 

    Private   Sub  WebBrowserl_DownloadComplete() '      ProgressBar 
    pbMain.Visible   =   False End  Sub 


    11.3.    Internet Explorer 

        WebBrowser     
  .    , , 
    Internet Explorer,    
  . 
       InternetExplorer     
  .    InternetExplorer    
     WebBrowser,  
    InternetExplorer. 

    11.3.1.  InternetExplorer 

     Visual Basic    Internet Explorer   
   ActiveX. Internet Explorer   ,   
      . 
     InternetExplorer   in-process  (  DLL) 
  . 

      InternetExplorer 

    Internet Explorer      ,    
 WebBrowser,   ,  WebBrowser  
.        
 . 


    276   Personal Web-Server 

         ,  
 InternetExplorer: 

    	 

    FullName	     , 
   Internet Explorer. 
    FullScreen	,     Internet Explorer 
  .                                                                                                     ! 
    MenuBar	    Internet Explorer. 
    Name	  Internet Explorer Microsoft. 
    StatusBar	    Internet Explorer. 
    StatusText	      . 
    Toolbar	    Internet Explorer.                 | 
     InternetExplorer    Quit. 
       ,   ,   
 InternetExplorer, .   "   WebBrowser"  
"   WebBrowser". 
     Internet Explorer      ActiveX,  
 Visual Basic      Microsoft 
Internet Controls.       References ( 
References  Project). 
        InternetExplorer    
 ,       Visual Basic:    
     InternetExplorer. 
             
Internet Explorer: 

    Dim  browser  As   InternetExplorer 
    Set  browser  =  CreateObject("InternetExplorer.Application") 

        ActiveX,    Internet Explorer 
 .    ,    True 
 Visible. 
           Web www.Microsoft.com: 

    browser.Visible   =   True 
    browser.Navigate   "http://www.Microsoft.com" 

             Sub Main() 
  ,        
, , . 

    11.4.   Personal Web-Server 

    Microsoft Personal Web-Server  Windows 95    
Windows 95  Web-       
Web-.     , Personal Web-Server (PWS) 
       , 
   Internet. PWS   ,   
 Web-. 
    Personal Web-Server      ,  
         
 Web. Personal Web-Server        
 Windows 95      Internet. 


     11.    Internet	277 


    11.4.1.  Personal Web-Server 

      Personal Web-Server   . 
 Personal Web-Server ,  : 
    	  Internet; 
    	   ; 
    	   . 

     Personal Web-Server    

         Personal Web-Server  
    .     
 Internet,       Internet   . 
            , 
   TCP/IP,   ,    
  .      Personal Web-Server. 
    :     ,   
  ,          
   . 

       

            . 
      . 
    :        
 Windows 95. 
    1.  Control Panel ( )     
Network (). 
    2.    Network   Configuration (). 
  TCP/IP   ,   , 
    Properties () (. 11.3.). 
    3.    2    TCP/IP Properties 
(: TCP/IP).   IP  ,   IP 
Address. : 
    )    ,       
 . 
    6)   Specify an IP address (  IP  ). 
    )       IP (, 123.45.6.78). 
    )     Subnet Mask ( ) ;   
  (. 11.4). 
    4.      WINS (Windows Integrated 
Name Server),   WINS Configuration ( WINS). : 
    )    ,       
 . 
    )    Enable WINS Resolution (  WINS). 
    )     Primary WINS Server (  WINS)  Secondary 
WINS Server (  WINS)   ,      (123.45.6.78). 
    )    Scope ID ( )  . 
    )  ,     (. 11.5). 


    278   Personal Web-Server 

    . 11.3.    Network. 
    . 11.4.    TCP/IP Properties   3. 


     11.    Internet 279 


    . 11.5.     TCP/IP Properties   4. 
    . 11.6.    TCP/IP Properties   5. 


    280 :      Internet 

    5.         
       IP, 
     DNS.    
,    DNS Configuration ( DNS). : 
    )    ,       
 . 
    )   Enable DNS ( DNS). 
    )      Host ( ). 
    )       (. 11.6). 
    6.  ,     Network (),    
Yes     . 

    11.4.2.  Personal Web-Server 

    1.  Control Panel,    Personal Web-Server 
 ,  Personal Web-Server,  FTP  HTTP . 
    2.   Startup  ,  Personal Web-Server 
.      Start. 
    3.   Services  ,    FTP  
Running.     FTP   Services    Start. 
    4.   Services ,    HTTP  Running. 
    HTTP   Services    Start. 

    11.5. :      Internet 

          ,   
 . 

    11.5.1.    


    WebBrowser     

         ,   
   ,      
   Web.       
 (. 11.7). 
    1.    Standard EXE. 
    2.       Toolbar, ImageList, 
Statusbar  Prog-ressBar.        
Microsoft Windows Common Controls 5.0,     . 
    3.    ProgressBar  Visible   False. 
    4.      WebBrowser.    
   Microsoft Internet Controls. 

       

    1.    (  Property Pages)  
 Toolbar       
 .         
- ( tbrPlaceholder) ,    
     . 


     11.    Internet 281 


    . 11.7.     WebBrowser. 

    2.       ,    
   URL        URL. 
      . 
    3.     ImageList    
 .  Toolbar    ImageList 
( General     Toolbar). 

    . 11.8.      . 


    282 :      Internet 

        : 

     	 

     ""	   Web-Browser. 
     ""	   ,    
 Web. 
     ""	     . 
     " "	   , 
   . 
     ""	     Web,   
 . 

       

    1.    AutoSize    sbrContent.  
   ,     , 
   ,   MinimumWidth.   
     ProgressBar. 
    2.   ,       
,    .    AutoSize 
 sbrSpring,        . 

    11.5.2.   

            . 
            
   . 

    :        
.      ,  , 
  ,      URL  
         . 


       WebBrowser 

    1.       : 
    )      ,    
  . 
    6)   Form_Load     GetSetting  
     .   
    : 

    	 

    appname	lAwareApp 
    section	Startup 
    key	StartPage 
    default	HomePage.HTML    (	App.Path). 

    )   Navigate  WebBrowser,    
 . 
    )     Form_Unload,   SaveSetting,   
    . 


     11.    Internet	283 

    2.    WebBrowser     : 
    )      Form_Resize. 
    )     WebBrowser ,    
     Toolbar    StatusBar. 

       WebBrowser 

    1.     URL    : 
    )        KeyPress   . 
    )   KeyPress    ( ASCII 13)    
       ,   
Navigate   WebBrowser    URL  
 Addltem    URL  . 
    )     Click   . 
    )      URL,     . 
    2.   : 
    )      ( Busy),   
ButtonClick          
   URL 
    )   ButtonClick      GoBack  
WebBrowser.   ,      
,    . 
            : 

    Private Sub tlbWeb_ ButtonClick(ByVal Button As Button) Select Case 
Button.Key Case "Back" 
    '      Case "Forward" 
    '      Case Else 
    '    End Select End Sub 


       ProgressBar 

    1.  ProgressBar    Statusbar.  
    ProgressBar    
StatusBar   ,      StatusBar: 
    )     . 
    6)        SetParent API. 
    Win32,     Declare  
 API Text Viewer,    Visual Basic (.  6 
"    "). 
    )   Form_Load,  SetParent API,    
    ProgressBar    StatusBar. 


    284 :      Internet 

    2.          ProgressBar: 
    )      DownloadBegin  
 WebBrowser. 
    )    ProgressBar   
0,   100    0. 
    )    ProgressBar    
 StatusBar     Visible  True. 
    3.       ProgressBar: 
    )      DownloadComplete  
 WebBrowser. 
    )   False  Visible   ProgressBar. 
    4.    ProgressBar    : 
    )      ProgressChange  
 WebBrowser. 
    6)   Progress   -1   ProgressMax   0, 
  Value   ProgressBar   
 . 

    :   ,   Progress, 
  MaxProgress    100. 

