I know there are a lot of UDP examples out there, but I really need to know specifically what I am doing wrong. I have Wireshark monitoring my data traffic and according to that program Unity is not sending data at all. Could some of you coding wizards look over this and help me find my mistake?
public class heatLampControl : MonoBehaviour { //Ben Stewart, june 6th, 2016 //this code controls the "Position" of the heat lamps, ie what angle the heat should be coming from. The // value will be added to a new UDP connection to the dSPACE machine //Update 6-10: Added UDP functionality, as accessing the UDP class that was created for this purpose turned out to not function correctly public float lampIntensity = 0.0f; //Multiplier for relative intensity of the sunlight GameObject sun; public GameObject player; // dropped in via GUI public bool isNight = false; // is it night? if so, heat lamp should turn off public double sunAngle; // angle about the y axis. that is the only angle that can be controlled. public bool isOn = false; public string keyDown; public int port; public string dataStr; byte[] data; public GameObject cycle; //following three keep track of day/night cycle public Day_Night.TimeOfDay tod; public Day_Night dayNight; public int strLength; private IPAddress ip; private UdpClient udp; private IPEndPoint ipep; public float fruitIntensity; public float hayIntensity; OlfactoryControl olfactory; string hostname; IPAddress[] ipList; void Start () { hostname = Dns.GetHostName (); ipList = Dns.GetHostEntry (hostname).AddressList; port = 13722; cycle = GameObject.Find ("DayNight"); dayNight = cycle.GetComponent<Day_Night> (); sun = this.gameObject; olfactory = GameObject.Find ("Olfactory").GetComponent<OlfactoryControl>(); ip = ipList [0]; ipep = new IPEndPoint (ip, port); udp = new UdpClient (13722); } // Update is called once per frame void Update () { sunAngle = player.transform.eulerAngles [1] - Math.Atan2 (sun.transform.position [2], sun.transform.position [0]);// gets the positional angle of the sun compared to the player keyDown = Input.inputString; if (isNight || Input.GetKeyUp (KeyCode.L)) { // IF L is pressed down, light will come on lampIntensity = 0f; isOn = false; } if (!isNight && Input.GetKeyDown (KeyCode.L)) { lampIntensity = 1f; isOn = true; } tod = dayNight.tod; // if (tod == Day_Night.TimeOfDay.Idle) // lampIntensity = 1.0f; // if (tod == Day_Night.TimeOfDay.SunRise) { // lampIntensity = (dayNight.timeOfDay / (dayNight.sunSet - dayNight.StartTime)); // } hayIntensity = olfactory.hayIntensity; fruitIntensity = olfactory.fruitIntensity; sendUdp (); } //june 30th edit void sendUdp(){ dataStr = hayIntensity.ToString () + fruitIntensity.ToString () + lampIntensity.ToString (); byte[] sendBytes = System.Text.Encoding.ASCII.GetBytes (dataStr); Debug.Log (dataStr); udp.Send (sendBytes, sendBytes.Length, ipep); Debug.Log ("Data sent to IP Address " + ip.ToString() + " on port " + port.ToString()); } }
june 30th edit
You know, these could be solved with git.\$\endgroup\$