.net2.0的BUG[附源码]

异步套接字操作.如果开始异步接受连接之后调用XML序列化,则会导致AcceptAsync失败,AcceptAsync的操作结果为SocketError.OperationAborted

 http://dl.dbank.com/c01remhgxr 这里可以下载源码.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using Common;
using System.Threading;

namespace Client
{
    public partial class ClientForm : Form
    {
        Socket Client = null;
        bool Run = true;

        public ClientForm()
        {
            InitializeComponent();
        }

        private delegate void ListBoxAHandler(ListBox control, object add);

        private void ListBoxAdd(ListBox control, object obj)
        {
            if (this.InvokeRequired)
            {
                ListBoxAHandler delegateMethod = new ListBoxAHandler(ListBoxAdd);
                this.Invoke(delegateMethod, new object[] { control, obj });
            }
            else
            {
                control.Items.Add(obj);
                control.SelectedIndex = control.Items.Count - 1;
            }
        }

        private void Btn_Connect_Click(object sender, EventArgs e)
        {
            try
            {
                

                this.Btn_Connect.Enabled = false;

                IPEndPoint remote = new IPEndPoint(IPAddress.Parse(this.Txt_IP.Text), ushort.Parse(this.Txt_Port.Text));

                Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                Client.Connect(remote);

                new Thread(new ParameterizedThreadStart(BeginReceive)).Start(Client);

                ListBoxAdd(this.Lst_Message, DateTime.Now + "->已成功链接到服务器");

                Run = true;

                this.Btn_DisConnect.Enabled = true;

                this.Btn_Send.Enabled = true;
            }
            catch (Exception ex)
            {

                ListBoxAdd(this.Lst_Message, DateTime.Now + "->连接服务器失败:" + ex.Message);

                this.Btn_DisConnect.Enabled = false;

                this.Btn_Connect.Enabled = true;

                this.Btn_Send.Enabled = false;
            }

        }

        private void Btn_DisConnect_Click(object sender, EventArgs e)
        {
            try
            {
                Run = false;

                this.Btn_DisConnect.Enabled = false;

                SocketHelper.CloseSocket(Client);

                ListBoxAdd(this.Lst_Message, DateTime.Now + "->已成功断开连接");

                this.Btn_Connect.Enabled = true;

                this.Btn_Send.Enabled = false;
            }
            catch
            {
            }
        }

        private void Btn_Send_Click(object sender, EventArgs e)
        {
            try
            {
                byte[] data = Encoding.UTF8.GetBytes(this.Txt_Send.Text);

                if (Client.Send(data) == data.Length)
                {
                    ListBoxAdd(this.Lst_Message, DateTime.Now + "->向服务器:" + Client.RemoteEndPoint + " 发送数据成功.");
                }
            }
            catch (Exception ex)
            {
                ListBoxAdd(this.Lst_Message, DateTime.Now + "->发送数据失败:" + ex.Message);
            }
        }

        private void Btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ClientForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Run = false;
            SocketHelper.CloseSocket(Client);
        }


        private void BeginReceive(object state)
        {
            try
            {
                if (!Run) return;

                SocketAsyncEventArgs args = new SocketAsyncEventArgs();

                args.Completed += new EventHandler<SocketAsyncEventArgs>(Asyn_Completed);

                args.UserToken = state;

                args.SetBuffer(new byte[1024], 0, 1024);

                if (!(state as Socket).ReceiveAsync(args))
                {
                    ReceiveCompleted(args);
                }
            }
            catch { }
        }

        private void Asyn_Completed(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                switch (e.LastOperation)
                {
                    case SocketAsyncOperation.Receive:
                        {
                            ReceiveCompleted(e);
                        }
                        break;
                    case SocketAsyncOperation.Disconnect:
                        {
                            if (e.UserToken != null && e.UserToken is Socket)
                            {
                                Socket socket = e.UserToken as Socket;

                                ListBoxAdd(this.Lst_Message, DateTime.Now + "->与服务器:" + socket.RemoteEndPoint + "断开连接");

                                Run = false;

                                this.Btn_DisConnect.Enabled = false;

                                SocketHelper.CloseSocket(Client);

                                this.Btn_Connect.Enabled = true;

                                this.Btn_Send.Enabled = false;
                            }
                        }
                        break;
                }
            }
            catch { }
        }


        private void ReceiveCompleted(SocketAsyncEventArgs e)
        {
            try
            {
                if (e.SocketError == SocketError.Success && e.BytesTransferred > 0)
                {
                    new Thread(new ParameterizedThreadStart(BeginReceive)).Start(e.UserToken);
                    Socket server = e.UserToken as Socket;
                    ListBoxAdd(
                        this.Lst_Message, DateTime.Now + "->收到服务器:" + server.RemoteEndPoint +
                        "发送的数据:" + Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred)
                        );

                }
            }
            catch { }
        }





    }

}
namespace Client
{
    partial class ClientForm
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Btn_Connect = new System.Windows.Forms.Button();
            this.Btn_DisConnect = new System.Windows.Forms.Button();
            this.Txt_IP = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.Txt_Port = new System.Windows.Forms.TextBox();
            this.Txt_Send = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.Btn_Send = new System.Windows.Forms.Button();
            this.Btn_Close = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.Lst_Message = new System.Windows.Forms.ListBox();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // Btn_Connect
            // 
            this.Btn_Connect.Location = new System.Drawing.Point(246, 15);
            this.Btn_Connect.Name = "Btn_Connect";
            this.Btn_Connect.Size = new System.Drawing.Size(75, 23);
            this.Btn_Connect.TabIndex = 0;
            this.Btn_Connect.Text = "连接";
            this.Btn_Connect.UseVisualStyleBackColor = true;
            this.Btn_Connect.Click += new System.EventHandler(this.Btn_Connect_Click);
            // 
            // Btn_DisConnect
            // 
            this.Btn_DisConnect.Enabled = false;
            this.Btn_DisConnect.Location = new System.Drawing.Point(327, 15);
            this.Btn_DisConnect.Name = "Btn_DisConnect";
            this.Btn_DisConnect.Size = new System.Drawing.Size(75, 23);
            this.Btn_DisConnect.TabIndex = 1;
            this.Btn_DisConnect.Text = "断开连接";
            this.Btn_DisConnect.UseVisualStyleBackColor = true;
            this.Btn_DisConnect.Click += new System.EventHandler(this.Btn_DisConnect_Click);
            // 
            // Txt_IP
            // 
            this.Txt_IP.Location = new System.Drawing.Point(45, 17);
            this.Txt_IP.Name = "Txt_IP";
            this.Txt_IP.Size = new System.Drawing.Size(100, 21);
            this.Txt_IP.TabIndex = 2;
            this.Txt_IP.Text = "127.0.0.1";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 21);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(23, 12);
            this.label1.TabIndex = 3;
            this.label1.Text = "IP:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(151, 20);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 12);
            this.label2.TabIndex = 4;
            this.label2.Text = "Port:";
            // 
            // Txt_Port
            // 
            this.Txt_Port.Location = new System.Drawing.Point(192, 17);
            this.Txt_Port.Name = "Txt_Port";
            this.Txt_Port.Size = new System.Drawing.Size(48, 21);
            this.Txt_Port.TabIndex = 5;
            this.Txt_Port.Text = "3333";
            // 
            // Txt_Send
            // 
            this.Txt_Send.Location = new System.Drawing.Point(45, 44);
            this.Txt_Send.Name = "Txt_Send";
            this.Txt_Send.Size = new System.Drawing.Size(195, 21);
            this.Txt_Send.TabIndex = 6;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(12, 47);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(35, 12);
            this.label3.TabIndex = 7;
            this.label3.Text = "数据:";
            // 
            // Btn_Send
            // 
            this.Btn_Send.Enabled = false;
            this.Btn_Send.Location = new System.Drawing.Point(246, 42);
            this.Btn_Send.Name = "Btn_Send";
            this.Btn_Send.Size = new System.Drawing.Size(75, 23);
            this.Btn_Send.TabIndex = 8;
            this.Btn_Send.Text = "发送";
            this.Btn_Send.UseVisualStyleBackColor = true;
            this.Btn_Send.Click += new System.EventHandler(this.Btn_Send_Click);
            // 
            // Btn_Close
            // 
            this.Btn_Close.Location = new System.Drawing.Point(327, 42);
            this.Btn_Close.Name = "Btn_Close";
            this.Btn_Close.Size = new System.Drawing.Size(75, 23);
            this.Btn_Close.TabIndex = 10;
            this.Btn_Close.Text = "关闭窗口";
            this.Btn_Close.UseVisualStyleBackColor = true;
            this.Btn_Close.Click += new System.EventHandler(this.Btn_Close_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.Lst_Message);
            this.groupBox1.Location = new System.Drawing.Point(14, 72);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(388, 186);
            this.groupBox1.TabIndex = 11;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "信息";
            // 
            // Lst_Message
            // 
            this.Lst_Message.FormattingEnabled = true;
            this.Lst_Message.HorizontalScrollbar = true;
            this.Lst_Message.ItemHeight = 12;
            this.Lst_Message.Location = new System.Drawing.Point(6, 20);
            this.Lst_Message.Name = "Lst_Message";
            this.Lst_Message.Size = new System.Drawing.Size(376, 160);
            this.Lst_Message.TabIndex = 10;
            // 
            // ClientForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(411, 268);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.Btn_Close);
            this.Controls.Add(this.Btn_Send);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.Txt_Send);
            this.Controls.Add(this.Txt_Port);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.Txt_IP);
            this.Controls.Add(this.Btn_DisConnect);
            this.Controls.Add(this.Btn_Connect);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Name = "ClientForm";
            this.Text = "客户端";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ClientForm_FormClosing);
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button Btn_Connect;
        private System.Windows.Forms.Button Btn_DisConnect;
        private System.Windows.Forms.TextBox Txt_IP;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox Txt_Port;
        private System.Windows.Forms.TextBox Txt_Send;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Button Btn_Send;
        private System.Windows.Forms.Button Btn_Close;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.ListBox Lst_Message;
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace Common
{
    public class Serializer
    {
        public static T ReadObject4XmlFile<T>(string path)
        {
            if (File.Exists(path))
            {
                XmlSerializer ser = new XmlSerializer(typeof(T));
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    return (T)ser.Deserialize(fs);
                }
            }
            return default(T);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;

namespace Common
{
    public class SocketHelper
    {
        public static void CloseSocket(Socket socket)
        {
            try
            {
                if (socket != null)
                {
                    if (socket.Connected)
                        socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }
            }
            catch { }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace Object
{
     [Serializable]
    public class PlugInList
    {
        public List<PlugInfo> List { get; set; }

        public PlugInList()
        {
            List = new List<PlugInfo>();
        }
    }

     [Serializable]
     public class PlugInfo
     {
         /// <summary>
         /// 插件路径
         /// </summary>
         public string Path { get; set; }
         /// <summary>
         /// 插件名称
         /// </summary>
         public string Name { get; set; }
         /// <summary>
         /// 类名
         /// </summary>
         public string Class { get; set; }
         /// <summary>
         /// 命令头
         /// </summary>
         public byte CommandHead { get; set; }

         public override string ToString()
         {
             return Name;
         }
     }
}


<?xml version="1.0"?>
<PlugInList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <List>
    <PlugInfo>
      <Path>PlugIn\PlugIn1.dll</Path>
      <Name>插件名称1</Name>
      <Class>PlugIn1.Program</Class>
      <CommandHead>1</CommandHead>
    </PlugInfo>
    <PlugInfo>
      <Path>PlugIn\PlugIn2.dll</Path>
      <Name>插件名称2</Name>
      <Class>PlugIn2.Program</Class>
      <CommandHead>2</CommandHead>
    </PlugInfo>
  </List>
</PlugInList>


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using Common;
using Object;

namespace TestDotNetBug
{
    public partial class ServerForm : Form
    {
        Socket Server = null;
        bool Run = true;

        public ServerForm()
        {
            InitializeComponent();
        }

        private delegate void ListBoxHandler(ListBox control, object obj);

        private void ListBoxAdd(ListBox control, object obj)
        {
            if (this.InvokeRequired)
            {
                ListBoxHandler delegateMethod = new ListBoxHandler(ListBoxAdd);
                this.Invoke(delegateMethod, new object[] { control, obj });
            }
            else
            {
                control.Items.Add(obj);
                control.SelectedIndex = control.Items.Count - 1;
            }
        }

        private void ListBoxSub(ListBox control, object obj)
        {
            if (this.InvokeRequired)
            {
                ListBoxHandler delegateMethod = new ListBoxHandler(ListBoxSub);
                this.Invoke(delegateMethod, new object[] { control, obj });
            }
            else
            {
                control.Items.Remove(obj);
                if (control.Items.Count > 0)
                    control.SelectedIndex = control.Items.Count - 1;
            }
        }

        private void Btn_Start_Click(object sender, EventArgs e)
        {
            try
            {
                this.Btn_Start.Enabled = false;

                Start();

                ListBoxAdd(this.Lst_Message, DateTime.Now + "->服务已启动");

                this.Btn_Stop.Enabled = true;

            }
            catch (Exception ex)
            {
                ListBoxAdd(this.Lst_Message, DateTime.Now + "->服务启动失败:" + ex.Message);

                this.Btn_Stop.Enabled = false;
                this.Btn_Start.Enabled = true;
            }
        }

        private void Btn_Stop_Click(object sender, EventArgs e)
        {
            try
            {
                this.Btn_Stop.Enabled = false;

                Stop();

                ListBoxAdd(this.Lst_Message, DateTime.Now + "->服务已停止");

                this.Btn_Start.Enabled = true;

                this.Btn_Send.Enabled = false;
            }
            catch
            {
                
            }
        }

        private void Btn_Send_Click(object sender, EventArgs e)
        {
            try
            {
                Socket socket = this.Lst_ClientList.SelectedItem as Socket;
                byte[] data = Encoding.UTF8.GetBytes(this.Txt_Send.Text);

                if (socket.Send(data) == data.Length)
                {
                    ListBoxAdd(this.Lst_Message, DateTime.Now + "->向客户端:" + socket.RemoteEndPoint + " 发送数据成功.");
                }
            }
            catch (Exception ex)
            {
                ListBoxAdd(this.Lst_Message, DateTime.Now + "->发送数据失败:" + ex.Message);
            }
        }

        private void Btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Lst_ClientList_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Btn_Send.Enabled = this.Lst_ClientList.SelectedIndex != -1;
        }

        private void ServerForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Run = false;
            Stop();
        }


        private void Start()
        {
            IPEndPoint local = new IPEndPoint(IPAddress.Parse(this.Txt_IP.Text), ushort.Parse(this.Txt_Port.Text));

            Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            Server.Bind(local);

            Server.Listen(ushort.MaxValue);

            Run = true;

            new Thread(new ThreadStart(Accept)).Start();

            //注释掉下面这一行代码,或者将下面一行代码放到new Thread(new ThreadStart(Accept)).Start();之前,将不会再出现socket异常.

            PlugInList list = Serializer.ReadObject4XmlFile<PlugInList>("PlugIn.xml");
        }

        private void Stop()
        {
            SocketHelper.CloseSocket(Server);

            foreach (Socket socket in this.Lst_ClientList.Items)
            {
                SocketHelper.CloseSocket(socket);
            }

            this.Lst_ClientList.Items.Clear();

            Run = false;
        }

        private void Accept()
        {
            try
            {
                if (!Run) return;

                SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                args.Completed += new EventHandler<SocketAsyncEventArgs>(Asyn_Completed);

                if (!Server.AcceptAsync(args))
                {
                    AcceptCompleted(args);
                }
            }
            catch { }
        }


        private void Asyn_Completed(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                switch (e.LastOperation)
                {
                    case SocketAsyncOperation.Accept:
                        {
                            AcceptCompleted(e);
                        }
                        break;
                    case SocketAsyncOperation.Receive:
                        {
                            ReceiveCompleted(e);
                        }
                        break;
                    case SocketAsyncOperation.Disconnect:
                        {
                            if (e.UserToken != null && e.UserToken is Socket)
                            {
                                Socket socket = e.UserToken as Socket;
                                ListBoxSub(this.Lst_ClientList, socket);
                                ListBoxAdd(this.Lst_Message, DateTime.Now + "->客户端:" + socket.RemoteEndPoint + "断开连接");
                            }
                        }
                        break;
                }
            }
            catch { }
        }

        private void AcceptCompleted(SocketAsyncEventArgs e)
        {
            try
            {
                new Thread(new ThreadStart(Accept)).Start();

                if (e.SocketError == SocketError.Success)
                {
                    ListBoxAdd(this.Lst_ClientList, e.AcceptSocket);
                    ListBoxAdd(this.Lst_Message, DateTime.Now + "->有客户端连接:" + e.AcceptSocket.RemoteEndPoint);
                    BeginReceive(e.AcceptSocket);
                }
                else
                {
                    //只是因为多反序列化了一个数据,导致AcceptAsync一直失败....
                    //如果注释掉第150行代码,将不会再出错,不知道是不是.net的Bug
                }
            }
            catch
            {

            }
            finally
            {
                
            }
        }

        private void BeginReceive(object state)
        {
            try
            {
                if (!Run) return;

                SocketAsyncEventArgs args = new SocketAsyncEventArgs();

                args.Completed += new EventHandler<SocketAsyncEventArgs>(Asyn_Completed);

                args.UserToken = state;

                args.SetBuffer(new byte[1024], 0, 1024);

                if (!(state as Socket).ReceiveAsync(args))
                {
                    ReceiveCompleted(args);
                }
            }
            catch { }
        }

        private void ReceiveCompleted(SocketAsyncEventArgs e)
        {
            try
            {
                if (e.SocketError == SocketError.Success && e.BytesTransferred > 0)
                {
                    new Thread(new ParameterizedThreadStart(BeginReceive)).Start(e.UserToken);
                    Socket client = e.UserToken as Socket;
                    ListBoxAdd(
                        this.Lst_Message, DateTime.Now + "->收到客户端:" + client.RemoteEndPoint +
                        "发送的数据:" + Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred)
                        );

                }
            }
            catch { }
        }
    }
}


namespace TestDotNetBug
{
    partial class ServerForm
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Txt_Port = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.Txt_IP = new System.Windows.Forms.TextBox();
            this.Btn_Stop = new System.Windows.Forms.Button();
            this.Btn_Start = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.Btn_Close = new System.Windows.Forms.Button();
            this.Lst_ClientList = new System.Windows.Forms.ListBox();
            this.Btn_Send = new System.Windows.Forms.Button();
            this.Txt_Send = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.Lst_Message = new System.Windows.Forms.ListBox();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.SuspendLayout();
            // 
            // Txt_Port
            // 
            this.Txt_Port.Location = new System.Drawing.Point(192, 17);
            this.Txt_Port.Name = "Txt_Port";
            this.Txt_Port.Size = new System.Drawing.Size(48, 21);
            this.Txt_Port.TabIndex = 11;
            this.Txt_Port.Text = "3333";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(151, 20);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 12);
            this.label2.TabIndex = 10;
            this.label2.Text = "Port:";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 21);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(23, 12);
            this.label1.TabIndex = 9;
            this.label1.Text = "IP:";
            // 
            // Txt_IP
            // 
            this.Txt_IP.Location = new System.Drawing.Point(45, 17);
            this.Txt_IP.Name = "Txt_IP";
            this.Txt_IP.Size = new System.Drawing.Size(100, 21);
            this.Txt_IP.TabIndex = 8;
            this.Txt_IP.Text = "127.0.0.1";
            // 
            // Btn_Stop
            // 
            this.Btn_Stop.Enabled = false;
            this.Btn_Stop.Location = new System.Drawing.Point(327, 15);
            this.Btn_Stop.Name = "Btn_Stop";
            this.Btn_Stop.Size = new System.Drawing.Size(75, 23);
            this.Btn_Stop.TabIndex = 7;
            this.Btn_Stop.Text = "停止服务";
            this.Btn_Stop.UseVisualStyleBackColor = true;
            this.Btn_Stop.Click += new System.EventHandler(this.Btn_Stop_Click);
            // 
            // Btn_Start
            // 
            this.Btn_Start.Location = new System.Drawing.Point(246, 15);
            this.Btn_Start.Name = "Btn_Start";
            this.Btn_Start.Size = new System.Drawing.Size(75, 23);
            this.Btn_Start.TabIndex = 6;
            this.Btn_Start.Text = "启动服务";
            this.Btn_Start.UseVisualStyleBackColor = true;
            this.Btn_Start.Click += new System.EventHandler(this.Btn_Start_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.Lst_ClientList);
            this.groupBox1.Location = new System.Drawing.Point(14, 72);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(131, 186);
            this.groupBox1.TabIndex = 12;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "客户端列表";
            // 
            // Btn_Close
            // 
            this.Btn_Close.Location = new System.Drawing.Point(327, 42);
            this.Btn_Close.Name = "Btn_Close";
            this.Btn_Close.Size = new System.Drawing.Size(75, 23);
            this.Btn_Close.TabIndex = 16;
            this.Btn_Close.Text = "关闭窗口";
            this.Btn_Close.UseVisualStyleBackColor = true;
            this.Btn_Close.Click += new System.EventHandler(this.Btn_Close_Click);
            // 
            // Lst_ClientList
            // 
            this.Lst_ClientList.DisplayMember = "RemoteEndPoint";
            this.Lst_ClientList.ItemHeight = 12;
            this.Lst_ClientList.Location = new System.Drawing.Point(6, 20);
            this.Lst_ClientList.Name = "Lst_ClientList";
            this.Lst_ClientList.Size = new System.Drawing.Size(120, 160);
            this.Lst_ClientList.TabIndex = 0;
            this.Lst_ClientList.SelectedIndexChanged += new System.EventHandler(this.Lst_ClientList_SelectedIndexChanged);
            // 
            // Btn_Send
            // 
            this.Btn_Send.Enabled = false;
            this.Btn_Send.Location = new System.Drawing.Point(246, 42);
            this.Btn_Send.Name = "Btn_Send";
            this.Btn_Send.Size = new System.Drawing.Size(75, 23);
            this.Btn_Send.TabIndex = 15;
            this.Btn_Send.Text = "发送";
            this.Btn_Send.UseVisualStyleBackColor = true;
            this.Btn_Send.Click += new System.EventHandler(this.Btn_Send_Click);
            // 
            // Txt_Send
            // 
            this.Txt_Send.Location = new System.Drawing.Point(45, 44);
            this.Txt_Send.Name = "Txt_Send";
            this.Txt_Send.Size = new System.Drawing.Size(195, 21);
            this.Txt_Send.TabIndex = 13;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(12, 47);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(35, 12);
            this.label3.TabIndex = 14;
            this.label3.Text = "数据:";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.Lst_Message);
            this.groupBox2.Location = new System.Drawing.Point(151, 72);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(250, 186);
            this.groupBox2.TabIndex = 17;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "信息";
            // 
            // Lst_Message
            // 
            this.Lst_Message.FormattingEnabled = true;
            this.Lst_Message.HorizontalScrollbar = true;
            this.Lst_Message.ItemHeight = 12;
            this.Lst_Message.Location = new System.Drawing.Point(6, 20);
            this.Lst_Message.Name = "Lst_Message";
            this.Lst_Message.Size = new System.Drawing.Size(238, 160);
            this.Lst_Message.TabIndex = 0;
            // 
            // ServerForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(411, 267);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.Btn_Close);
            this.Controls.Add(this.Btn_Send);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.Txt_Send);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.Txt_Port);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.Txt_IP);
            this.Controls.Add(this.Btn_Stop);
            this.Controls.Add(this.Btn_Start);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Name = "ServerForm";
            this.Text = "服务端";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ServerForm_FormClosing);
            this.groupBox1.ResumeLayout(false);
            this.groupBox2.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox Txt_Port;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox Txt_IP;
        private System.Windows.Forms.Button Btn_Stop;
        private System.Windows.Forms.Button Btn_Start;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Button Btn_Close;
        private System.Windows.Forms.ListBox Lst_ClientList;
        private System.Windows.Forms.Button Btn_Send;
        private System.Windows.Forms.TextBox Txt_Send;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.ListBox Lst_Message;
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值