Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using UnityEngine;
using System;
using System.Collections;
using System.Net;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using MiniJSON;
public class UDPReceive : MonoBehaviour
CharactorActor c_actor;
int LOCAL_PORT = 22222;
static UdpClient udp;
Thread thread;
public string parameter;
public static Action<string> DataCallBack;
void Start ()
UDPReceive.DataCallBack += Method;
public void UDPStart(){
udp = new UdpClient(LOCAL_PORT);
thread = new Thread(new ThreadStart(ThreadMethod));
public void Method(string data){
parameter = data;
void OnApplicationQuit()
private static void ThreadMethod()
IPEndPoint remoteEP = null;
byte[] data = udp.Receive(ref remoteEP);
string text = Encoding.ASCII.GetString(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.