日期:2014-05-20  浏览次数:20872 次

关于TcpListener 程序提示每个套节字地址(协议/网络地址/端口)只允许使用一次
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.Threading;
using   System.Runtime.InteropServices;  

namespace   FtpServer
{
///   <summary>
///   Form1   的摘要说明。
///   </summary>
public   class   FtpServerForm   :   System.Windows.Forms.Form
{
private   System.Windows.Forms.GroupBox   groupBox1;
private   System.Windows.Forms.Label   label1;
private   System.Windows.Forms.Label   label2;
private   System.Windows.Forms.Button   btnStop;
private   System.Windows.Forms.Button   btnStart;
private   System.Windows.Forms.ListBox   lbClients;
private   System.Windows.Forms.TextBox   tbSocketPort;
private   System.Windows.Forms.TextBox   tbClientsNum;
public   const   string   ROOTDIR   =   "c:\\ ";
//服务器可以支持最多的连接数
public   const   int   MAXNUM   =   100;
//clients   数组保存当前在线
//internal   允许同一个命名空间中的类访问
//   Hashtable     表示键/值对的集合,这些键/值对根据键的哈希代码进行组织。
internal   static   Hashtable   client   =   new   Hashtable();
//该服务器默认的监听端口号
                  public   TcpListener   tcpListener;
//开始服务的标志
internal   static   bool   SocketServiceFlag   =   false;
//服务器的ip地址
internal   string   ip;
internal   int   port;
///   <summary>
///   必需的设计器变量。
///   </summary>
private   System.ComponentModel.Container   components   =   null;

public   FtpServerForm()
{
//
//   Windows   窗体设计器支持所必需的
//
InitializeComponent();

//
//   TODO:   在   InitializeComponent   调用后添加任何构造函数代码
//
}

///   <summary>
///   清理所有正在使用的资源。
///   </summary>
protected   override   void   Dispose(   bool   disposing   )
{
if(   disposing   )
{
if   (components   !=   null)  
{
components.Dispose();
}
}
base.Dispose(   disposing   );
}

#region   Windows   窗体设计器生成的代码
///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   InitializeComponent()
{
this.groupBox1   =   new   System.Windows.Forms.GroupBox();
this.lbClients   =   new   System.Windows.Forms.ListBox();
this.label1   =   new   System.Windows.Forms.Label();
this.label2   =   new   System.Windows.Forms.Label();
this.tbSocketPort   =   new   System.Windows.Forms.TextBox();
this.tbClientsNum   =   new   System.Windows.Forms.TextBox();
this.btnStart   =   new   System.Windows.Forms.Button();
this.btnStop   =   new   System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//