Skip to content

Instantly share code, notes, and snippets.

@nenjiru
Created August 8, 2019 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nenjiru/b6c0ade8a123441e176719e11e6cbb09 to your computer and use it in GitHub Desktop.
Save nenjiru/b6c0ade8a123441e176719e11e6cbb09 to your computer and use it in GitHub Desktop.
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine;
public class UDPReceive : MonoBehaviour
{
static UdpClient udp;
Thread thread;
void Start()
{
udp = new UdpClient(3333);
thread = new Thread(new ThreadStart(ThreadMethod));
thread.Start();
}
void OnApplicationQuit()
{
udp.Close();
thread.Abort();
}
static void ThreadMethod()
{
while (true)
{
IPEndPoint remoteEP = null;
byte[] data = udp.Receive(ref remoteEP);
string text = Encoding.ASCII.GetString(data);
Debug.Log(text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment