Skip to content

Commit 9ddfda7

Browse files
committed
testing webgl port checking
1 parent 5abfee5 commit 9ddfda7

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using System.Diagnostics;
99
using System.Drawing; // for notifyicon
1010
using System.IO;
11+
using System.Net;
12+
using System.Net.NetworkInformation;
1113
using System.Runtime.InteropServices;
1214
using System.Threading;
1315
using System.Threading.Tasks;
@@ -1940,9 +1942,13 @@ private void BtnClearBuildReport_Click(object sender, RoutedEventArgs e)
19401942

19411943
private void MenuStartWebGLServer_Click(object sender, RoutedEventArgs e)
19421944
{
1943-
// runs unity SimpleWebServer.exe and launches default Browser into project build/ folder'
1944-
19451945
var proj = GetSelectedProject();
1946+
LaunchWebGL(proj);
1947+
}
1948+
1949+
// runs unity SimpleWebServer.exe and launches default Browser into project build/ folder'
1950+
void LaunchWebGL(Project proj)
1951+
{
19461952
var projPath = proj?.Path.Replace('/', '\\');
19471953
if (string.IsNullOrEmpty(projPath) == true) return;
19481954

@@ -1970,13 +1976,37 @@ private void MenuStartWebGLServer_Click(object sender, RoutedEventArgs e)
19701976
Random rnd = new Random();
19711977
int port = rnd.Next(50000, 61000);
19721978

1979+
// check if port is available https://stackoverflow.com/a/2793289
1980+
//bool isAvailable = true;
1981+
//IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
1982+
//IPEndPoint[] objEndPoints = ipGlobalProperties.GetActiveTcpListeners();
1983+
1984+
//// compare with existing ports, if available
1985+
//foreach (IPEndPoint tcpi in objEndPoints)
1986+
//{
1987+
// if (tcpi.Port == port)
1988+
// {
1989+
// isAvailable = false;
1990+
// break;
1991+
// }
1992+
//}
1993+
1994+
bool serverLaunched = false;
1995+
1996+
//if (isAvailable == false)
1997+
//{
1998+
// Console.WriteLine("failed to open port " + port + " (should be open already, or something else is using it?)");
1999+
//}
2000+
//else
2001+
//{
19732002
// take process id from unity, if have it (then webserver closes automatically when unity is closed)
19742003
var proc = ProcessHandler.Get(proj.Path);
19752004
int pid = proc == null ? -1 : proc.Id;
19762005
var param = "\"" + webExe + "\" \"" + buildPath + "\" " + port + (pid == -1 ? "" : " " + pid); // server exe path, build folder and port
2006+
// TODO take process reference, so can check if its already running
2007+
serverLaunched = Tools.LaunchExe(monoExe, param);
2008+
//}
19772009

1978-
// then open browser
1979-
var serverLaunched = Tools.LaunchExe(monoExe, param);
19802010
if (serverLaunched == true)
19812011
{
19822012
Tools.OpenURL("http://localhost:" + port);

0 commit comments

Comments
 (0)