@@ -7,12 +7,13 @@ namespace WebServer
7
7
{
8
8
public partial class WebServer : Form
9
9
{
10
- private double version = 2.4 ;
10
+ private double version = 2.6 ;
11
11
Server mainServer ;
12
12
private string pathToServe ;
13
13
private int port = 8080 ;
14
14
private bool running = false ;
15
- private string localHostURL = "http://localhost:8080/" ;
15
+ private string localHostURL = "http://127.0.0.1:8080/" ;
16
+ private bool actionInProgress = false ;
16
17
public WebServer ( )
17
18
{
18
19
InitializeComponent ( ) ;
@@ -26,18 +27,24 @@ public WebServer()
26
27
this . UpdateVersion . Visible = true ;
27
28
this . UpdateVersion . Text = "Version " + version + " is out!" ;
28
29
} ) ;
30
+ this . running = true ;
31
+ actionInProgress = true ;
32
+ toggleServer ( ) ;
33
+ actionInProgress = false ;
29
34
}
30
35
private void toggleServer ( )
31
36
{
32
37
if ( this . running )
33
38
{
39
+ this . Status . Text = "Running" ;
34
40
startServer ( ) ;
35
41
}
36
42
else if ( mainServer != null )
37
43
{
38
44
mainServer . Terminate ( ) ;
39
45
mainServer = null ;
40
46
this . URL . Visible = false ;
47
+ this . Status . Text = "Not Running" ;
41
48
this . MSG . Text = "Not Running" ;
42
49
this . MSG . Visible = true ;
43
50
}
@@ -47,7 +54,7 @@ private void startServer()
47
54
this . MSG . Visible = false ;
48
55
this . URL . Visible = true ;
49
56
mainServer = new Server ( pathToServe , port , PUT . Checked , DELETE . Checked , CORS . Checked , AutoIndex . Checked , ListDirectory . Checked ) ;
50
- this . localHostURL = "http://localhost :" + port + "/" ;
57
+ this . localHostURL = "http://127.0.0.1 :" + port + "/" ;
51
58
this . URL . Text = "Open " + this . localHostURL + " in your browser" ;
52
59
}
53
60
private void saveSettings ( )
@@ -122,19 +129,17 @@ private void loadSettings()
122
129
}
123
130
this . ServingPath . Text = "Currently Serving: " + pathToServe ;
124
131
this . Port . Value = new decimal ( new int [ ] { port , 0 , 0 , 0 } ) ;
125
- this . localHostURL = "http://localhost :" + port + "/" ;
132
+ this . localHostURL = "http://127.0.0.1 :" + port + "/" ;
126
133
this . URL . Text = "Open " + this . localHostURL + " in your browser" ;
127
134
}
128
135
catch ( Exception e ) { }
129
136
}
130
- bool actionInProgress = false ;
131
137
private void button1_Click ( object sender , EventArgs e )
132
138
{
133
139
if ( actionInProgress ) return ;
134
140
actionInProgress = true ;
135
141
running = ! running ;
136
142
toggleServer ( ) ;
137
- this . Status . Text = running ? "Running" : "Not Running" ;
138
143
actionInProgress = false ;
139
144
}
140
145
0 commit comments