图1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//使用Socket引用的命名空间
using System.Net.Sockets;
//绑定端口号引用的命名空间
using System.Net;
//打開線程引用的命名空間
using System.Threading;
public class UDPSocket
{
Socket mySocket;
/// <summary>
/// 接收的数据的数组
/// </summary>
byte[] ReciveDataBytes;
/// <summary>
/// 声明线程
/// </summary>
Thread reciveThread;
/// <summary>
/// 是否开启线程
/// </summary>
private bool IsThreading;
/// <summary>
/// 声明有个代理
/// </summary>
/// <param name="buffer">接收到的数据</param>
/// <param name="ReciveLength">接收到的数据的数组长度</param>
/// <param name="port">端口号</param>
/// <param name="ip">IP地址</param>
public delegate void ReciveDelegate(byte[] buffer, int ReciveLength, int port, string ip);
/// <summary>
/// 声明一个代理
/// </summary>
ReciveDelegate reciveDelegate;
/// <summary>
/// 构造方法重写
/// </summary>
/// <param name="temReciveDelegate">代理方法</param>
/// <param name="port">端口号</param>
/// <param name="reciveLength">接收到的数据的长度