⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 C常用算法程序集,一部比较经典的程序算法合集
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace mychatserver
{
    public delegate void OutDelegate(string text);

    public partial class Form1 : Form
    {
        IOxml xml1;
        public Form1()
        {

            InitializeComponent();
            xml1 = new IOxml();               
                 
        }

        controlserver control1;
        Thread addnewthread;

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            string ip = textBox2.Text;
          int port =Convert .ToInt32 ( textBox3.Text);
            xml1.create(ip , port );
          //  SaveConfigServer(ip, port);
        }

       
        private void button1_Click(object sender, EventArgs e)//启动服务器
        {
            control1 = new controlserver();
            control1.havenewuser = new OutDelegate(addcurrentnewclient);
            addnewthread=new Thread (new ThreadStart (control1.startserver));
            addnewthread.Start();
        }

     public void addcurrentnewclient(string str)
        {
            if (this.listBox1 .InvokeRequired)
            {

                OutDelegate outdelgate = new OutDelegate(addcurrentnewclient);
                this.listBox1 .Invoke(outdelgate, new object[] { str });
                return;
            }

            this.listBox1.Items.Add(str);

        }

     private void button2_Click(object sender, EventArgs e)
     {
         if (addnewthread != null)
         {
             addnewthread.Abort();
             control1.client.Stop();
         }
         
     }

     private void button3_Click(object sender, EventArgs e) //广播
     {

       string content= textBox1.Text;
       Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
       server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
       IPEndPoint iep = new IPEndPoint(IPAddress.Broadcast, 9052);//也可以IPAddress .Parse ("192.168.1.255")
       byte[] messagecontent = Encoding.Unicode .GetBytes (textBox1 .Text );

       server.SendTo(messagecontent , iep);

       server.Close();
        

     }

     private void Form1_FormClosing(object sender, FormClosingEventArgs e)
     {
         Application.Exit();

     }

       

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -