UDP サーバー - Himeyama/Unity_memo GitHub Wiki
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
public class udp : MonoBehaviour{
public int port = 8089;
UdpClient client;
Thread thread;
public long ln;
void Start(){
client = new UdpClient(port);
// udp.Client.ReceiveT
thread = new Thread(new ThreadStart(UDPThreadMethod));
thread.Start();
}
void OnApplicationQuit(){
thread.Abort();
}
void UDPThreadMethod(){
for(;;){
IPEndPoint remoteEP = null;
byte[] data = client.Receive(ref remoteEP);
string text = Encoding.ASCII.GetString(data);
ln = int.Parse(text);
Debug.Log(text);
}
}
void Update(){
}
}