Created
August 9, 2014 09:16
-
-
Save hemslo/ce2fc32c4b872124f2ce 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; | |
using System.Net; | |
using System.Net.Sockets; | |
using System.Text; | |
public class UDPListener | |
{ | |
private const int listenPort = 5000; | |
private static void StartListener() | |
{ | |
UdpClient listener = new UdpClient(listenPort); | |
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any,listenPort); | |
try | |
{ | |
while (true) | |
{ | |
Console.WriteLine("Waiting for UDP"); | |
byte[] bytes = listener.Receive( ref groupEP); | |
string str = Encoding.ASCII.GetString(bytes, 0, bytes.Length); | |
string[] words = str.Split(','); | |
Console.WriteLine("Received broadcast from {0} :\n {1}\n", | |
groupEP.ToString(), | |
str); | |
float x = float.Parse(words[0]); | |
float y = float.Parse(words[1]); | |
float z = float.Parse(words[2]); | |
bool s = bool.Parse(words[3]); | |
if (s) { | |
Console.WriteLine("11111111111111111111111111111111"); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.ToString()); | |
} | |
finally | |
{ | |
listener.Close(); | |
} | |
} | |
public static int Main() | |
{ | |
StartListener(); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment