发送端UDPSend
注意事项:发送端的IP为,你要发送到电脑的IP
注意事项:Send函数中的port值,发送与接受端要一致
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
public class UDPSend : MonoBehaviour
{
private readonly string ip = "127.0.0.1"; //主机ip地址
private IPAddress ipAddress;
private IPEndPoint endPoint;
private Socket socket;
private EndPoint server;
private byte[] sendData; //发送内容,转化为byte字节
//发送函数
public void Send(int value,int port) //参数不是字符串时转化为string
{
string msg = value.ToString(); //传递的值转化为string
try
{
ipAddress = IPAddress.Parse(ip