网站首页站长博客下载中心域名交易站长论坛域名主机免费电邮免费域名中文排行排名查询站长书库书籍教程下载
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
学院首页 网络编程 网页设计 图形图象 数 据 库 服 务 器 网络媒体 网络安全 个人专栏 站长CLUB 业界新闻 信息公告
 当前位置:首页 >> 网络编程 >> NET专区 >> 正文
公告通知
返回上级列表
资料搜索
相关文章
Delphi开发单机瘦数据库程序要点
Delphi Shell
 在DELPHI中更简单的存取JPEG文件
delphi一句话帮助
Delphi中两个BUG的分析与修复 
Delphi的组件读写机制 
delphi8里在VCL.net使用Ado.net 
 创建快捷方式到 [启动]
 创建快捷方式到 [启动]
用Delphi2005和DUnit搭建敏捷开发
构造.NET环境下的网页下载器 (2)
[ 来源:转载 | 作者:无从考证 | 时间:2005-11-3 10:29:38 | 浏览:人次 ]
收藏到新浪ViVi 收藏到365KEY 收藏到我摘  字号选择〖    〗/ 双击滚屏 单击停止  
三.网页下载器实例介绍: 
   
    最后,我就综合以上.NET网络编程的一些知识,向大家展示一个很好的实例。该实例是一个运用Socket的基于同步模式的客户端应用程序,它首先通过解析服务器的IP地址建立一个终结点,同时创建一个基于流套接字的Socket连接,其运用的协议是TCP协议。通过该Socket就可以发送获取网页的命令,再通过该Socket获得服务器上默认的网页,最后通过文件流将获得的数据写入本机文件。这样就完成了网页的下载工作了,程序运行的效果如下所示: 
    
   
   
  程序的代码如下: 
   
  using System; 
  using System.Drawing; 
  using System.Collections; 
  using System.ComponentModel; 
  using System.Windows.Forms; 
  using System.Data; 
  using System.Net; 
  using System.Net.Sockets; 
  using System.Text; 
  using System.IO; 
   
  namespace SocketSample 
  { 
   ///  
   /// Form1 的摘要说明。 
   /// 
 
   
   public class Form1 : System.Windows.Forms.Form 
   { 
   private System.Windows.Forms.Label label1; 
   private System.Windows.Forms.Label label2; 
   private System.Windows.Forms.Button Download; 
   private System.Windows.Forms.TextBox ServerAddress; 
   private System.Windows.Forms.TextBox Filename; 
   ///  
   /// 必需的设计器变量。 
   /// 
 
   private System.ComponentModel.Container 
   components = null; 
   public Form1() 
   { 
   // 
   // Windows 窗体设计器支持所必需的 
   // 
   InitializeComponent(); 
   
   // 
   // TODO: 在 InitializeComponent 
   // 调用后添加任何构造函数代码 
   } 
   
   ///  
   /// 清理所有正在使用的资源。 
   /// 
 
   protected override void Dispose( bool disposing ) 
   { 
   if( disposing ) 
   { 
   if (components != null) 
   { 
   components.Dispose(); 
   } 
   } 
   base.Dispose( disposing ); 
   } 
   
   #region Windows Form Designer generated code 
   ///  
   /// 设计器支持所需的方法 - 不要使用代码编辑器修改 
   /// 此方法的内容。 
   /// 
 
   private void InitializeComponent() 
   { 
   this.label1 = new System.Windows. 
   Forms.Label(); 
   this.label2 = new System.Windows. 
   Forms.Label(); 
   this.Download = new System.Windows. 
   Forms.Button(); 
   this.ServerAddress = new System.Windows. 
   Forms.TextBox(); 
   this.Filename = new System.Windows. 
   Forms.TextBox(); 
   this.SuspendLayout(); 
   // 
   // label1 
   // 
   this.label1.Location = new System.Drawing. 
   Point(16, 24); 
   this.label1.Name = "label1"; 
   this.label1.Size = new System.Drawing. 
   Size(80, 23); 
   this.label1.TabIndex = 0; 
   this.label1.Text = "服务器地址:"; 
   this.label1.TextAlign = System.Drawing. 
   ContentAlignment.MiddleRight; 
   // 
   // label2 
   // 
   this.label2.Location = new System.Drawing. 
   Point(16, 64); 
   this.label2.Name = "label2"; 
   this.label2.Size = new System.Drawing. 
   Size(80, 23); 
   this.label2.TabIndex = 1; 
   this.label2.Text = "本地文件名:"; 
   this.label2.TextAlign = System.Drawing. 
   ContentAlignment.MiddleRight; 
   // 
   // Download 
   // 
   this.Download.Location = new System. 
   Drawing.Point(288, 24); 
   this.Download.Name = "Download"; 
   this.Download.TabIndex = 2; 
   this.Download.Text = "开始下载"; 
   this.Download.Click += new System. 
   EventHandler(this.Download_Click); 
   // 
   // ServerAddress 
   // 
   this.ServerAddress.Location = new System. 
   Drawing.Point(96, 24); 
   this.ServerAddress.Name = "ServerAddress"; 
   this.ServerAddress.Size = new System. 
   Drawing.Size(176, 21); 
   this.ServerAddress.TabIndex = 3; 
   this.ServerAddress.Text = ""; 
   // 
   // Filename 

本新闻共2页,当前在第1页  1  2  


[发送给好友]  [打印本页]  [关闭窗口]  [返回顶部]   转载请注明来源:http://edu.chinaz.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
栏目编辑: 设计风 责任编辑: 简若宁
原始作者: 无从考证 录入时间: 2005-11-3 10:29:38
信息来源: 转载 投稿信箱: Edu#chinaz.com
设为首页 - 加入收藏 - 关于我们 - 广告服务 - 版权申明 - 友情链接 - 联系方式 - 总编信箱 - 会员投稿