发送端:
调用Send()方法,传递发送的内容。
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 string ip = "192.168.0.77"; //主机ip地址
private IPAddress ipAddress;
private IPEndPoint endPoint;
private Socket socket;
private EndPoint server;
private byte[] sendData; //发送内容,转化为byte字节
//发送函数
public void Send(int value) //参数不是字符串时转化为string
{
string msg = value.ToString(); //传递的值转化为string
try
{
ipAddress = IPAddress.Parse(ip); //ip地址
endPoint = new IPEndPoint(ipAddress, 112); //自定义端口号
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType