SPUPTestScriptHTTP.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. public class SPUPTestScriptHTTP : MonoBehaviour
  6. {
  7. //var
  8. public SerialPortUtility.SerialPortUtilityPro serialPort = null;
  9. private int httpreq = 0;
  10. // Use this for initialization
  11. void Start () {}
  12. void Update()
  13. {
  14. if (httpreq == 2)
  15. {
  16. //request
  17. if (serialPort != null)
  18. {
  19. System.Threading.Thread.Sleep(10);
  20. serialPort.WriteCRLF("HTTP/1.1 200 OK");
  21. serialPort.WriteCRLF("Date: Mon, 04 Feb 2019 09:23:07 GMT");
  22. serialPort.WriteCRLF("Server: SerialPort Utility Pro");
  23. serialPort.WriteCRLF("Connection: close");
  24. serialPort.WriteCRLF("Content-Type: text/html");
  25. serialPort.WriteCRLF("");
  26. serialPort.WriteCRLF("<!DOCTYPE html><html><body>Serial Port Utility Pro</body></html>");
  27. serialPort.WriteCRLF("");
  28. System.Threading.Thread.Sleep(100);
  29. serialPort.Close();
  30. serialPort.Open();
  31. }
  32. httpreq = 0;
  33. }
  34. }
  35. //for class
  36. public void ReadComprateHTTP(object data)
  37. {
  38. var httpdat = data as String;
  39. Debug.Log(httpdat);
  40. if (httpdat.IndexOf("GET / ") >= 0)
  41. {
  42. httpreq++;
  43. }
  44. if (httpdat == "")
  45. {
  46. httpreq++;
  47. }
  48. }
  49. }