Closed asenyurt closed 3 years ago
Each time the server starts, reset it:
try {
//validation checks
if (string.IsNullOrWhitespace(txtHost.Text)) return;
if (!int.TryParse(txtPort.Text, out var port)) return;
//start requirements
var ip = IPAddress.Parse(txtHost.Text);
//IP validation check
if (ip == null) return;
//create the server
var server = new SimpleTcpServer();
//attempt server start
server.Start(ip, port);
}
catch(Exception ex) {
MessageBox.Show($"An error occurred whilst starting the server:\n\n{ex}");
}
You also don't need to directly specify an IP Address if you're positive the first valid adapter will be correct:
//start the server by using the port only
server.Start(port);
TL;DR: Always ensure you check for nulls and invalid values
Hi when i click the start button its give me Null error from server.Start(ip, Convert.ToInt32(txtPort.Text)); ip is correct host is correct but i dont understand why i am getting error