Created
August 8, 2019 03:49
-
-
Save nenjiru/b6c0ade8a123441e176719e11e6cbb09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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