资源简介

服务器客户端UDP广播通话


【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
namespace NetServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //使用UDP协议发送数据
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //设置端口号
            IPEndPoint ieps = new IPEndPoint(IPAddress.Broadcast, 8900);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
            //将发送数据转换为字节数组
            byte[] bytess = System.Text.Encoding.Unicode.GetBytes(textBox1.Text);
            socket.SendTo(bytess, ieps);
            socket.Close();
        }
    }
}

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace NetClient
{
    public class AddMessageEventArgs : EventArgs
    {
        public string mess;
    }

   public class ClassListener
    {
        private Thread ths;
        private EndPoint eps;
        private string receiveDatas;
        private Socket socket;
        public event EventHandler OnAddMessAge;
        public ClassListener() { }
        //开始监听
        public void StartListen()
        {
            ths = new Thread(new ThreadStart(Listen));
            ths.Start();
        }
        //停止监听
        public void Stop()
        {
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      11264  2020-05-26 20:30  NetClient\NetClient\bin\Debug\NetClient.exe

     文件      38400  2020-05-26 20:30  NetClient\NetClient\bin\Debug\NetClient.pdb

     文件      21464  2020-05-27 10:41  NetClient\NetClient\bin\Debug\NetClient.vshost.exe

     文件        490  2012-06-06 02:06  NetClient\NetClient\bin\Debug\NetClient.vshost.exe.manifest

     文件       1846  2009-09-18 12:39  NetClient\NetClient\ClassListener.cs

     文件       1933  2009-10-08 12:01  NetClient\NetClient\Form1.cs

     文件       4040  2009-09-18 20:20  NetClient\NetClient\Form1.Designer.cs

     文件       6690  2009-09-18 20:20  NetClient\NetClient\Form1.resx

     文件       3962  2020-05-26 20:27  NetClient\NetClient\NetClient.csproj

     文件       6801  2020-05-26 20:30  NetClient\NetClient\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       2467  2020-05-27 10:41  NetClient\NetClient\obj\Debug\NetClient.csproj.FileListAbsolute.txt

     文件        847  2020-05-26 20:30  NetClient\NetClient\obj\Debug\NetClient.csproj.GenerateResource.Cache

     文件      11264  2020-05-26 20:30  NetClient\NetClient\obj\Debug\NetClient.exe

     文件        180  2020-05-26 20:30  NetClient\NetClient\obj\Debug\NetClient.Form1.resources

     文件      38400  2020-05-26 20:30  NetClient\NetClient\obj\Debug\NetClient.pdb

     文件        180  2020-05-26 20:30  NetClient\NetClient\obj\Debug\NetClient.Properties.Resources.resources

     文件       4608  2020-05-26 20:30  NetClient\NetClient\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        490  2009-09-18 12:15  NetClient\NetClient\Program.cs

     文件       1350  2009-09-18 12:15  NetClient\NetClient\Properties\AssemblyInfo.cs

     文件       2858  2020-05-26 20:27  NetClient\NetClient\Properties\Resources.Designer.cs

     文件       5612  2009-09-18 12:15  NetClient\NetClient\Properties\Resources.resx

     文件       1109  2020-05-26 20:27  NetClient\NetClient\Properties\Settings.Designer.cs

     文件        249  2009-09-18 12:15  NetClient\NetClient\Properties\Settings.settings

     文件        917  2020-05-26 20:27  NetClient\NetClient.sln

    ..A..H.     17408  2009-10-08 12:02  NetClient\NetClient.suo

    ..A..H.     40448  2020-05-27 10:43  NetClient\NetClient.v11.suo

     文件       9216  2020-05-26 20:29  NetServer\NetServer\bin\Debug\NetServer.exe

     文件      32256  2020-05-26 20:29  NetServer\NetServer\bin\Debug\NetServer.pdb

     文件      21464  2020-05-27 10:38  NetServer\NetServer\bin\Debug\NetServer.vshost.exe

     文件        490  2012-06-06 02:06  NetServer\NetServer\bin\Debug\NetServer.vshost.exe.manifest

............此处省略42个文件信息

评论

共有 条评论