只贴代码,自己研究,已经测试过!
using UnityEngine;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using UnityEngine.UI;
public class BroadCast : MonoBehaviour
{
private Button btnServer;
private Button btnClient;
private Button btnExit;
private Text txt;
private string strInfo;
private int port = 6677;
const string specialText = "123!!@@##$$%%-MessageFormServerBroadCast";
bool serverIsRun = false;
bool clientIsRun = false;
Thread serverThread = null;
UdpClient UdpSend = null;
Thread clientThread = null;
UdpClient UdpListen = null;
float flowedime = 0;
void StartServer()//服务器一直发消息
{
strInfo = "Starting Server...";
if (serverThread != null && serverThread.IsAlive) return;
serverThread = new Thread(()=>