Skip to content

Instantly share code, notes, and snippets.

@nenjiru
Created August 8, 2019 03:48
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/7eb142e10e4facda35de55f27b8b15cd to your computer and use it in GitHub Desktop.
Save nenjiru/7eb142e10e4facda35de55f27b8b15cd to your computer and use it in GitHub Desktop.
using System.Net.Sockets;
using System.Text;
using UnityEngine;
public class UDPSender : MonoBehaviour
{
private UdpClient client;
void Start()
{
client = new UdpClient();
client.Connect("localhost", 3333);
}
void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 100, 40), "Send"))
{
byte[] dgram = Encoding.UTF8.GetBytes("hello!");
client.Send(dgram, dgram.Length);
}
}
void OnApplicationQuit()
{
client.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment