以下我的代码:
using System ; 
using System.Drawing ; 
using System.Collections ; 
using System.ComponentModel ; 
using System.Windows.Forms ; 
using System.Data ; 
using System.Net.Sockets ; 
using System.Net;namespace windows
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.StatusBar statusBar1; private System.ComponentModel.Container components = null; int port = 8000 ; 
//定义侦听端口号 
private TcpClient tcpc ; 
//对服务器端创建TCP连接 
private Socket stSend ; 
//创建发送数据套接字 
private bool tcpConnect = false ; 
//定义标识符,用以表示TCP连接是否建立  public Form1()
{
InitializeComponent();
} protected override void Dispose ( bool disposing ) 

if ( tcpConnect ) 

Byte [ ] bySend = new byte [ 4 ] ; 
//根据字符串“STOP”长度来定义Byte数组 
bySend = System.Text.Encoding. 
Default.GetBytes ( "STOP" ) ; 
int i = stSend.Send ( bySend ) ; 
//发送控制码 
stSend.Close ( ) ; 
//关闭套接字 

if ( disposing ) 

if ( components != null ) 

components.Dispose ( ) ; 


base.Dispose ( disposing ) ; 

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
 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.label3 = new System.Windows.Forms.Label();
 this.button2 = new System.Windows.Forms.Button();
 this.statusBar1 = new System.Windows.Forms.StatusBar();
 this.SuspendLayout();
 // 
 // label1
 // 
 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地址:";
 // 
 // textBox1
 // 
 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 = "192.168.0.2";
 // 
 // button1
 // 
 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);
 // 
 // label2
 // 
 this.label2.Location = new System.Drawing.Point(16, 64);
 this.label2.Name = "label2";
 this.label2.TabIndex = 3;
 this.label2.Text = "发送信息:";
 // 
 // textBox2
 // 
 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 = "zhb1";
 // 
 // listBox1
 // 
 this.listBox1.ItemHeight = 12;
 this.listBox1.Items.AddRange(new object[] {
   "219.243.47.9"});
 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;
 // 
 // label3
 // 
 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 = "已经发送的信息:";
 // 
 // button2
 // 
 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);
 // 
 // statusBar1
 // 
 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 = 10;
 this.statusBar1.Text = "statusBar1";
 // 
 // Form1
 // 
 this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
 this.ClientSize = new System.Drawing.Size(370, 317);
 this.Controls.Add(this.statusBar1);
 this.Controls.Add(this.button2);
 this.Controls.Add(this.listBox1);
 this.Controls.Add(this.textBox2);
 this.Controls.Add(this.label2);
 this.Controls.Add(this.button1);
 this.Controls.Add(this.textBox1);
 this.Controls.Add(this.label1);
 this.Controls.Add(this.label3);
 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
 this.MaximizeBox = false;
 this.Name = "Form1";
 this.Text = "利用Socket来发送数据";
 this.ResumeLayout(false);  } 
   
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{

    //以下代码是判断是否和远程终结点成功连接 
try 

stSend = new Socket ( AddressFamily.InterNetwork , 
SocketType.Stream , ProtocolType.Tcp ) ; 
//初始化一个Socket实例 
IPEndPoint tempRemoteIP = new IPEndPoint 
( IPAddress.Parse ( textBox1.Text ) , port ) ; 
//根据IP地址和端口号创建远程终结点 
EndPoint epTemp = ( EndPoint ) tempRemoteIP ; 
stSend.Connect ( epTemp ) ; 
//连接远程主机的8000端口号 
statusBar1.Text = "成功连接远程计算机!" ; 
tcpConnect = true ; 
button1.Enabled = false ; 
button2.Enabled = true ; 

catch ( Exception ) 

statusBar1.Text = "目标计算机拒绝连接请求!" ; 


} private void button2_Click(object sender, System.EventArgs e)
{
int iLength = textBox2.Text.Length ; 
//获取要发送的数据的长度 
Byte [ ] bySend = new byte [ iLength ] ; 
//根据获取的长度定义一个Byte类型数组 
bySend = System.Text.Encoding.Default.GetBytes 
( textBox2.Text ) ; 
//按照指定编码类型把字符串指定到指定的Byte数组 
int i = stSend.Send ( bySend ) ; 
//发送数据 
listBox1.Items.Add ( textBox2.Text ) ;  }
}
}...........................................................................
 
结果当我点  连接  按钮时
总是出现"目标计算机拒绝连接请求! "
我输入的IP : 192.168.0.2 是我自己的电脑地址.ping 192.168.0.2是通的,为什么呀?