Created
March 4, 2019 20:51
-
-
Save j3ffgray/20307a93f06bbd46e67502256791dc95 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 UnityEngine; | |
using System; | |
using System.Net; | |
using System.Net.Sockets; | |
using System.Text; | |
public class UdpSrvrSample : MonoBehaviour { | |
public static void Main() { | |
byte[] data = new byte[1024]; | |
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050); | |
UdpClient newsock = new UdpClient(ipep); | |
Debug.Log("Waiting for a client..."); | |
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); | |
data = newsock.Receive(ref sender); | |
Debug.Log("Message received from {0}:" + sender.ToString()); | |
Debug.Log(Encoding.ASCII.GetString(data, 0, data.Length)); | |
string welcome = "Welcome to my test server"; | |
data = Encoding.ASCII.GetBytes(welcome); | |
newsock.Send(data, data.Length, sender); | |
while(true) | |
{ | |
data = newsock.Receive(ref sender); | |
Debug.Log(Encoding.ASCII.GetString(data, 0, data.Length)); | |
newsock.Send(data, data.Length, sender); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment