Created
August 8, 2019 03:48
-
-
Save nenjiru/7eb142e10e4facda35de55f27b8b15cd 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.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