using System.Collections;
using System.Collections.Generic;
using System;
using System.Net;
using System.Net.Sockets;
using UnityEngine;
namespace FGUFW.Core
{
public static class UdpBroadcastUtility
{
public const int BROADCAST_PORT = 31410;
public const int LOCAL_PORT = 31411;
private static UdpClient sendClient,receiveClient;
private static IPEndPoint broadcastIEP;
public static Action<byte[]> OnReceive;
public static byte[] receiveBuffer;
public static void Init()
{
if(broadcastIEP!=null)
{
return;
}
broadcastIEP = new IPEndPoint(IPAddress.Broadcast,BROADCAST_PORT);
sendClient = new UdpClient(LOCAL_PORT);
receiveClient = new UdpClient(BROADCAST_PORT);
receive();
}
public static async void Send(byte[] data)
{
try
{
unity Udp示例
Unity UDP通信教程
最新推荐文章于 2024-01-05 10:44:58 发布
本文将介绍如何在Unity中实现UDP通信,包括设置UDP客户端和服务器,进行数据发送与接收的详细步骤,帮助开发者理解Unity中网络编程的基本概念。

最低0.47元/天 解锁文章
7117





