导读:
三.本文介绍程序的设计、调试、运行的软件环境
(1).微软公司视窗2000服务器版
(2).Visual Studio .Net正式版,.Net FrameWork SDK版本号3705
四.利用Socket来传送数据: Visual C#在使用Socket传送数据时要注意下列问题的解决方法:
1.创建Socket实例,使用此实例创建和远程终结点的连接,并判断连接是否成功建立。
2.发送数据到Socket,实现数据传送。
这些问题解决方法都可以在下面介绍代码中找到相对应的部分。由于下面的代码都有详细的注解,
这里就不详细介绍。下面是利用Socket传送数据的具体实现步骤:
1.启动Visual Studio .Net,并新建一个Visual C#项目,
项目名称为【利用Socket来发送数据】。
2.把Visual Studio .Net的当前窗口切换到【Form1.cs(设计)】窗口,
并从【工具箱】中的【Windows窗体组件】选项卡中往Form1窗体中拖入下列组件,并执行相应操作:
二个TextBox组件,一个用以输入远程主机的IP地址,一个用以输入往远程主机传送的数据。
一个StausBar组件,用以显示程序的运行状况。
一个ListBox组件,用以显示程序已传送的数据信息。
三个Label组件。
二个Button组件,名称分别为button1、button2,并在这二个组件被拖入窗体后,分别双击它们,则系统会在Form1.cs文件中自动产生这二个组件的Click事件对应的处理代码。
3.【解决方案资源管理器】窗口中,双击Form1.cs文件,进入Form1.cs文件的编辑界面。
4.以下面代码替代系统产生的InitializeComponent过程:
private void InitializeComponent ( )
{
this.label1 = new System.Windows.Forms.Label ( ) ;
this.textBox1 = new System.Windows.Forms.TextBox ( ) ;
this.button1 = new System.Windows.Forms.Button ( ) ;
this.label2 = new System.Windows.Forms.Label ( ) ;
this.textBox2 = new System.Windows.Forms.TextBox ( ) ;
this.listBox1 = new System.Windows.Forms.ListBox ( ) ;
this.statusBar1 = new System.Windows.Forms.StatusBar ( ) ;
this.label3 = new System.Windows.Forms.Label ( ) ;
this.button2 = new System.Windows.Forms.Button ( ) ;
this.SuspendLayout ( ) ;
this.label1.Location = new System.Drawing.Point ( 24 , 20 ) ;
this.label1.Name = "label1" ;
this.label1.Size = new System.Drawing.Size ( 74 , 30 ) ;
this.label1.TabIndex = 0 ;
this.label1.Text = "IP地址:" ;
this.textBox1.BorderStyle = System.Windows.
Forms.BorderStyle.FixedSingle ;
this.textBox1.Location = new System.Drawing.Point ( 94 , 18 ) ;
this.textBox1.Name = "textBox1" ;
this.textBox1.Size = new System.Drawing.Size ( 166 , 21 ) ;
this.textBox1.TabIndex = 1 ;
this.textBox1.Text = "" ;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat ;
this.button1.Location = new System.Drawing.Point ( 280 , 14 ) ;
this.button1.Name = "button1" ;
this.button1.Size = new System.Drawing.Size ( 62 , 28 ) ;
this.button1.TabIndex = 2 ;
this.button1.Text = "连接" ;
this.button1.Click += new System.EventHandler ( this.button1_Click ) ;
this.label2.Location = new System.Drawing.Point ( 16 , 64 ) ;
this.label2.Name = "label2" ;
this.label2.TabIndex = 3 ;
this.label2.Text = "发送信息:" ;
this.textBox2.BorderStyle = System.Windows.
Forms.BorderStyle.FixedSingle ;
this.textBox2.Location = new System.Drawing.Point ( 94 , 58 ) ;
this.textBox2.Name = "textBox2" ;
this.textBox2.Size = new System.Drawing.Size ( 166 , 21 ) ;
this.textBox2.TabIndex = 4 ;
this.textBox2.Text = "" ;
this.listBox1.ItemHeight = 12 ;
this.listBox1.Location = new System.Drawing.Point ( 20 , 118 ) ;
this.listBox1.Name = "listBox1" ;
this.listBox1.Size = new System.Drawing.Size ( 336 , 160 ) ;
this.listBox1.TabIndex = 6 ;
this.statusBar1.Location = new System.Drawing.Point ( 0 , 295 ) ;
this.statusBar1.Name = "statusBar1" ;
this.statusBar1.Size = new System.Drawing.Size ( 370 , 22 ) ;
this.statusBar1.TabIndex = 7 ;
this.statusBar1.Text = "无连接" ;
this.label3.Location = new System.Drawing.Point ( 14 , 94 ) ;
this.label3.Name = "label3" ;
this.label3.Size = new System.Drawing.Size ( 128 , 23 ) ;
this.label3.TabIndex = 8 ;
this.label3.Text = "已经发送的信息:" ;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat ;
this.button2.Location = new System.Drawing.Point ( 280 , 54 ) ;
this.button2.Name = "button2" ;
this.button2.Size = new System.Drawing.Size ( 62 , 28 ) ;
this.button2.TabIndex = 9 ;
this.button2.Text = "发送" ;
this.button2.Click += new System.EventHandler
( this.button2_Click ) ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ;
this.ClientSize = new System.Drawing.Size ( 370 , 317 ) ;
this.Controls.AddRange ( new System.Windows.Forms.Control[] {
this.button2 ,
this.statusBar1 ,
this.listBox1 ,
this.textBox2 ,
this.label2 ,
this.button1 ,
this.textBox1 ,
this.label1 ,
this.label3} ) ;
this.FormBorderStyle = System.
Windows.Forms.FormBorderStyle.FixedSingle ;
this.MaximizeBox = false ;
this.Name = "Form1" ;
this.Text = "利用Socket来发送数据" ;
this.ResumeLayout ( false ) ;
}
至此【利用Sokcet来传送数据】项目设计后的界面就完成了,具体如图01所示:
图01:【利用Sokcet来传送数据】项目的设计界面
5.在Form1.cs文件的开头的导入命名空间的代码区,添加下列代码,
下列代码是导入下面程序中使用到的类所在的命名空间:
本文转自
http://study.qqcf.com/web/224/23996.htm
分享到:
相关推荐
本文详细介绍Visual C#中利用托管Socket实现网络数据传送和接收的实现方法及其注意事项。
Visual C#使用DirectX实现视频播放
asp.net Visual C#.Net 网络程序开发-Socket篇
• 学习Visual C#.Net Socket类的使用 • 学习基本UI控件的使用 • 学习多线程的开发 • 学习聊天室的原理
第2章 Visual C# 2008与图形图像 第3章 Visual C#2008与多媒体 第4章 Visual C#2006与数据库 第5章 Visual C#2008的SQL查询与图表技朮 第6章 Visualc#2008的打印与水晶报表技术 第7章 VisualC#2008与Windows系统...
Your hands-on guide to Visual C# fundamentals Expand your expertise—and teach yourself the fundamentals of Microsoft Visual C# 2013. If you have previous programming experience but are new to Visual ...
Visual C# and Databases is a tutorial that provides a detailed introduction to using Visual C# for accessing and maintaining databases. Topics covered include: database structure, database design, ...
Visual C# 2008程序设计经典案例设计与实现
Visual C# 示例 源码Visual C# 示例 源码Visual C# 示例 源码Visual C# 示例 源码Visual C# 示例 源码Visual C# 示例 源码Visual C# 示例 源码Visual C# 示例 源码Visual C# 示例 源码Visual C# 示例 源码Visual C# ...
visual c# 2008程序设计经典案例设计与实现》
《高等学校计算机应用规划教材:Visual C# 2010程序设计教程》详细介绍了Visual C# 2010程序设计的基础知识、基本方法和应用技巧,共分14章,主要内容包括.NET平台与Visual Studio 2010开发环境、C#语言基础及面向...
Visual C#2010新增了大量可圈可点的丰富特性,《Visual C# 2010从入门到精通:Step by Step》围绕着基础知识和这些新特性全面介绍了如何利用Visual Studio2010和.NET Framework 4.O编写应用程序。书中沿袭深受读者...
应用程序设计编制(Visual C#平台)Visual C# .NET试题汇编(程序员级)
Visual C#常用函数和方法集汇总 Visual C#常用函数和方法集汇总 Visual C#常用函数和方法集汇总
完全手册Visual C# 2008开发技术详解
\Visual C#使用DirectX实现视频播放 很不错哦 希望笑纳啊
本书是一本讲解如何通过Visual C#.NET开发应用软件的书籍,它以5个实际项目为依托,全面而系统地再现了项目开发的实际过程,具有很大的实用价值和参考意义。 全书首先介绍SQL Server 2000基础知识、ADO.NET基础...
Visual C# Homework Projects: A Computer Programming Tutorial by Philip Conrod English | 7 Aug. 2017 | ASIN: B074N8QQG3 | 920 Pages | AZW3 | 23.48 MB Visual C# programming concepts are taught while ...
Visual C# 2005从入门到精通,初学者必备资料;
在Visual C#下实现图像的透明处理.doc在Visual C#下实现图像的透明处理.doc在Visual C#下实现图像的透明处理.doc在Visual C#下实现图像的透明处理.doc在Visual C#下实现图像的透明处理.doc