| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | public class WebServerComponent : MonoBehaviour |
| | 4 | | { |
| | 5 | | static SimpleHTTPServer _server; |
| | 6 | | string wwwPath; |
| | 7 | | const int PORT = 9991; |
| | 8 | |
|
| | 9 | | void Awake() |
| | 10 | | { |
| 0 | 11 | | if (_server == null) |
| | 12 | | { |
| 0 | 13 | | var appPath = Application.dataPath; |
| 0 | 14 | | wwwPath = appPath + "/TestWebserverRoot"; |
| 0 | 15 | | _server = new SimpleHTTPServer(wwwPath, PORT); |
| 0 | 16 | | Debug.Log("Starting web server... (" + wwwPath + ")"); |
| | 17 | | } |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | public void Restart() |
| | 21 | | { |
| 0 | 22 | | if (_server == null) |
| | 23 | | { |
| 0 | 24 | | Awake(); |
| 0 | 25 | | } |
| | 26 | | else |
| | 27 | | { |
| 0 | 28 | | _server.Restart(wwwPath, PORT); |
| | 29 | | } |
| 0 | 30 | | } |
| | 31 | |
|
| | 32 | | void OnDestroy() |
| | 33 | | { |
| 0 | 34 | | if (_server == null) |
| | 35 | | { |
| 0 | 36 | | _server.Stop(); |
| | 37 | | } |
| 0 | 38 | | } |
| | 39 | | } |