I'm working on a small project and I'm having an issue. I have it set up so a user can paste a series of IP Addresses into a multiline textbox and ping each IP. I'm currently taking each value that's entered into the input box and adding it to a string array. The problem I'm having is converting each value in that array to an IP using the IPAddress.Parse method. Any tips would be greatly appriciated. It's in c#
using System;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.Net;
namespace MultiPing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pingBtn_Click(object sender, EventArgs e)
{
try
{
int i;
string[] allLines = inputBox.Text.Split('\n');
Ping pingSender = new Ping();
for (i = 0; i < allLines.Length; i++)
{
try
{
IPAddress address = IPAddress.Parse(allLines[]);
PingReply reply = pingSender.Send(address);
if (reply.Status == IPStatus.Success)
{
outputBox.Text = address + " is up \n";
}
else
{
outputBox.Text = address + " is down \n";
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
Change this
IPAddress address = IPAddress.Parse(allLines[]);
to
IPAddress address = IPAddress.Parse(allLines[i]);
Related
I need to close udp client connection without getting error says: "Cannot access object disposed" that is an exception.
This is
RehearsalStart.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Net.NetworkInformation;
using EntitiesLayer;
using BusinessLogicLayer;
using System.Data.SqlClient;
namespace PresentationLayer
{
public partial class RehearsalStart : Form
{
IPEndPoint Broadcast; //IP address endpoint representing a broadcast
IPEndPoint Any; //IP address endpoint representing any address
IPEndPoint PIC; //IP address endpoint representing the PIC we are connected to
IPEndPoint Origin; // IP address endpoint representing the source of the input data
bool Connected; //Indicates if there is a connection with any PIC
byte[] codQuestion = { (byte)'P', (byte)'C' }; //Array of bytes that is broadcast as a search code
UdpClient SocketALL; //PC socket in UDP
//Delegates used
public delegate void AsyncCallback(IAsyncResult ar);
public delegate void AddList(string o);
public string type;
public string name;
public string surname;
//Constructor
public RehearsalStart(string Type, string Name, string Surname)
{
type = Type;
name = Name;
surname = Surname;
InitializeComponent();
label1.Text = type + ": " + name + " " + surname;
}
private void RehearsalStart_Load(object sender, EventArgs e)
{
Connected = false;
try
{
SocketALL = new UdpClient();
Broadcast = new IPEndPoint(IPAddress.Broadcast, 30303);
Any = new IPEndPoint(IPAddress.Any, 30303);
SocketALL.Client.Bind(Any);
SocketALL.BeginReceive(ReceiveBrodcast, SocketALL);
SocketALL.Send(codQuestion, codQuestion.Length, Broadcast);
} catch (Exception ex){
throw ex;
}
public void ReceiveBrodcast(IAsyncResult ar)
{
string MAC = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString();
MAC = MAC[0].ToString() + MAC[1].ToString() + "-" + MAC[2].ToString() + MAC[3].ToString() + "-" + MAC[4].ToString() + MAC[5].ToString() + "-" + MAC[6].ToString() + MAC[7].ToString() + "-" + MAC[8].ToString() + MAC[9].ToString() + "-" + MAC[10].ToString() + MAC[11].ToString();
UdpClient MyUDP = (UdpClient)ar.AsyncState;
string Data = Convert(MyUDP.EndReceive(ar, ref Origin));
MyUDP.BeginReceive(ReceiveBrodcast, MyUDP);
switch (Data)
{
case "PC":
SocketALL.Send(Convert(name_textBox.Text + "\r\n" + MAC), name_textBox.Text.Length + 2 + MAC.Length, Broadcast);
break;
default:
Data = Origin.Address.ToString() + "\n" + Data.Replace("\r\n", "\n");
disp_listView.Invoke(new AddList(AddDisp), Data);
break;
}
}
public void AddDisp(string o)
{
for (int n = 0; n < disp_listView.Items.Count; n++)
{
if (disp_listView.Items[n].SubItems[0].Text == (o.Split('\n'))[0])
{
return;
}
}
disp_listView.Items.Add(new ListViewItem(o.Split('\n')));
}
private void Search_button_Click(object sender, EventArgs e)
{
disp_listView.Items.Clear();
try
{
SocketALL.Send(codQuestion, codQuestion.Length, Broadcast);
}
catch (Exception ex)
{
throw ex;
}
}
string Convert(byte[] a)
{
return Encoding.ASCII.GetString(a);
}
byte[] Convert(string a)
{
return Encoding.ASCII.GetBytes(a);
}
private void disp_listView_SelectedIndexChanged(object sender, EventArgs e)
{
if (!Connected && disp_listView.SelectedItems.Count != 0 && disp_listView.SelectedItems[0].SubItems[1].Text[0] == 'A')
{
button4.Enabled = false;
button3.Enabled = true;
}
else
{
button4.Enabled = false;
button3.Enabled = false;
}
}
private void button3_Click(object sender, EventArgs e)
{
PIC = new IPEndPoint(IPAddress.Parse(disp_listView.SelectedItems[0].SubItems[0].Text), 3000);
button4.Enabled = true;
button3.Enabled = false;
Connected = true;
disp_listView.Enabled = false;
Main Win = new Main(type, name, surname, number, PIC);
Win.ShowDialog();
button4.Enabled = false;
button3.Enabled = true;
Connected = false;
disp_listView.Enabled = true;
Close();
}
private void button4_Click(object sender, EventArgs e)
{
button4.Enabled = false;
button3.Enabled = true;
Connected = false;
disp_listView.Enabled = true;
System.Windows.Forms.Application.Exit();
}
}
And Main.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Net.NetworkInformation;
using EntitiesLayer;
using BusinessLogicLayer;
using System.Data.SqlClient;
namespace PresentationLayer
{
public partial class Main : Form
{
string type;
string name;
string surname;
//Members
int packs = 0;
UdpClient SocketPIC;
IPEndPoint Origin;
public delegate void AsyncCallback(IAsyncResult ar);
public delegate void Values(byte[] bytes);
//Methods
public Main()
{
InitializeComponent();
}
public Main(string Type, string Name, string Surname, int Number, IPEndPointP)
{
type = Type;
name = Name;
surname = Surname;
InitializeComponent();
SocketPIC = new UdpClient(3000);
SocketPIC.Connect(P);
SocketPIC.BeginReceive(ReceiveFrame, SocketPIC);
packs_timer.Enabled = true;
}
private void packs_timer_Tick(object sender, EventArgs e)
{
packs = 0;
SocketPIC.Send(new byte[] { 101, 0, 0, 0, 0 }, 5);
}
public void ReceiveFrame(IAsyncResult ar)
{
UdpClient MyUDP = (UdpClient)ar.AsyncState;
if (MyUDP.Client != null)
{
byte[] Data = MyUDP.EndReceive(ar, ref Origin);
MyUDP.BeginReceive(ReceiveFrame, MyUDP);
this.Invoke(new Values(AddData), Data);
}
}
private void CloseFrame(IAsyncResult ar)
{
UdpClient MyUDP = (UdpClient)ar.AsyncState;
try
{
if (MyUDP.Client != null) //ERROR
{
MyUDP.EndReceive(ar, ref Origin); //ERROR
MyUDP.Close(); //ERROR
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (SocketPIC.Client != null)
{
SocketPIC.EndReceive(ar, ref Origin);
SocketPIC.Close();
}
}
}
public void AddData(byte[] data)
{
if (data[0] == 102 && packs < 5)
{
for (int n = 1; n < data.Length; n += 12)
{
MEASURE.Add_I1(data[n], data[n + 1]);
MEASURE.Add_V1(data[n + 2], data[n + 3]);
MEASURE.Add_I2(data[n + 4], data[n + 5]);
MEASURE.Add_V2(data[n + 6], data[n + 7]);
MEASURE.Add_I3(data[n + 8], data[n + 9]);
MEASURE.Add_V3(data[n + 10], data[n + 11]);
}
packs++;
}
else
{
SocketPIC.Send(new byte[] { 102, 0, 0, 0, 0 }, 5);
//ADDING DATA
}
private void button_state_Click(object sender, EventArgs e)
{
if (button_state.Text == "Pause")
{
button_state.Text = "Continue";
packs_timer.Enabled = false;
}
else
{
button_state.Text = "Pause";
packs_timer.Enabled = true;
}
}
private void file_data_U_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
packs_timer.Enabled = false;
SocketPIC.Send(new byte[] { 102, 0, 0, 0, 0 }, 5);
SocketPIC.BeginReceive(CloseFrame, SocketPIC); //HERE is the error
RehearsalStart screen = new Rehearsal(type, name, surname);
screen.Show();
Close();
/*
packs_timer.Enabled = false;
SocketPIC.Send(new byte[] { 102, 0, 0, 0, 0 }, 5);
SocketPIC.Close();
Close();
*/
}
}
}
How may I fix this issue? I need to close udp client connection every time I disconnect and connect when I'm navigating between RehearsalStart and Main forms.
I'm working with an electronic board in c#.
I try to read OMRON plc's DM table with a C# WPF application beacuse I have to visualize live datas from the machine.
I can read messages via UDP, but I dont know how to read the DM table from the PLC. (PLC's settings are okay, that is ready to the FINS communication)
Here is my code for reading messages via UDP:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;
namespace OMRON_FINS
{
public partial class Form2 : Form
{
UdpClient Client = new UdpClient(9600); // PORT number
string data = "";
public Form2()
{
InitializeComponent();
textBox1.Text = GetLocalIPAddress();
}
public static string GetLocalIPAddress()
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
throw new Exception("No network adapters with an IPv4 address in the system!");
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Client.BeginReceive(new AsyncCallback(recv), null);
label5.Text = "Reading....";
}
catch (Exception ex)
{
richTextBox1.Text += ex.Message.ToString();
}
}
public void recv(IAsyncResult res)
{
IPEndPoint RemoteIP = new IPEndPoint(IPAddress.Any, 60240);
byte[] received = Client.EndReceive(res, ref RemoteIP);
data = Encoding.UTF8.GetString(received);
this.Invoke(new MethodInvoker(delegate
{
richTextBox1.Text += "\nReceived data: " + data;
}));
Client.BeginReceive(new AsyncCallback(recv), null);
}
}
}
Is there any example or guide to read the DM table?
Thanks!
I am testing a real-time port view for serial port.
The Form1 and debug state with always false is shown below.
When Form1 is created, the COM port list is stored in recordedPorts and timer1_Tick event is generated every 100ms, the current COM port list is read and stored in presentPorts and compared with recordedPorts. If you look at the debug state picture, you can see that the result value string[] each of GetPortNames() method is the same.
I want to display COM ports in comboBox1 in real time.
However, it could not be displayed in the comboBox1.
There was a problem in string operation, so timer1_Tick event could not be operated normally.
The first question is to know why string real-time comparison is always false,
and the second is whether there is any other way to display the serial port in real time.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace TestSerial
{
public partial class Form1 : Form
{
string[] recordedPorts, presentPorts;
string str;
public Form1()
{
InitializeComponent();
recordedPorts = SerialPort.GetPortNames();
foreach (string PortName in recordedPorts)
{
comboBox1.Items.Add(PortName);
}
}
private void button2_Click(object sender, EventArgs e)
{
if(serialPort1.IsOpen == true)
{
serialPort1.Close();
textBox1.Text += "disconnected." + Environment.NewLine;
}
else
{
textBox1.Text += "already disconnected." + Environment.NewLine;
}
}
private void button1_Click(object sender, EventArgs e)
{
if(serialPort1.IsOpen == false)
{
serialPort1.PortName = comboBox1.SelectedItem.ToString();
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.StopBits = StopBits.One;
serialPort1.Parity = Parity.None;
//serialPort1.Open();
try
{
serialPort1.Open(); //serial port open!!!
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
serialPort1.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
textBox1.Text += "connected." + Environment.NewLine;
serialPort1.WriteLine("abcd\r\n");
}
else
{
textBox1.Text += "already connected." + Environment.NewLine;
}
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
str = serialPort1.ReadExisting();
if(str.Length > 8)
{
textBox1.SelectedText += str + Environment.NewLine;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
presentPorts = SerialPort.GetPortNames();
if (presentPorts.Count() == 0)
{
//if(comboBox1.Items.Count != 0) comboBox1.Items.Clear();
recordedPorts = presentPorts;
return;
}
if (recordedPorts != presentPorts)
{
comboBox1.DataSource = presentPorts;
recordedPorts = presentPorts;
}
}
}
}
The debug state that is always false is as follows.
Thanks to Klaus Gütter.
I resolved this question by comparing the content of the arrays instead of the array references.
Change it to the code below and it works normally.
if (!recordedPorts.SequenceEqual(presentPorts))
//if (recordedPorts != presentPorts)
{
comboBox_port.DataSource = presentPorts;
recordedPorts = presentPorts;
}
New to WinForms but not ASP.NET or C#. Trying to make client/server app. Successfully received data from client on server but having troubles displaying it on server program winform. Codes are:
Server App code:
using System;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
namespace Server_App
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 1234); //configure host
TcpListenerEx listener = new TcpListenerEx(ep); //set host to listen
if (!listener.Active)
{
listener.Start();
}
while (true)
{
const int byteSize = 1024 * 1024;
byte[] message = new byte[byteSize];
var s = listener.AcceptTcpClient();
s.GetStream().Read(message, 0, byteSize); //obtaining network stream and receiving data through .Read()
message = cleanMessage(message);
string g = System.Text.Encoding.UTF8.GetString(message);
addMessage(g);
}
}
private void addMessage(string m)
{
this.textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + m;
}
private byte[] cleanMessage(byte[] rawMessageByte)
{
byte[] cleanMessage = rawMessageByte.Where(b => b != 0).ToArray();
return cleanMessage;
}
}
}
Client App code:
using System;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClientApp
{
public partial class ClientApp : Form
{
public ClientApp()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var message = System.Text.Encoding.UTF8.GetBytes(txtFromClient.Text);
using (var client = new TcpClient("127.0.0.1", 1234))//make connection with the host
{
NetworkStream stream = client.GetStream();/*obtain network stream*/
stream.Write(message, 0, message.Length);
}
}
private void textBox1_Click(object sender, EventArgs e)
{
txtFromClient.Text = "";
}
}
}
Everything is happening as planned except for displaying received data on server program's Form1's textbox. On debugging, I confirmed the correct value received in variable m of line this.textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + m;. Only problem is that this value cannot be displayed and hence seen on the Form1 of server program.
With the help and guidance from #AdrianoRepetti, solution to the given problem was furnished through the following code:
using System;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Linq;
namespace Server_App
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
backgroundWorker1.WorkerReportsProgress = true;
}
private void button1_Click(object sender, EventArgs e)
{
IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 1234); //configure host
if(!backgroundWorker1.IsBusy)
{
backgroundWorker1.RunWorkerAsync(ep); //called to start a process on the worker thread and send argument (listener) to our workerprocess.
}
}
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
IPEndPoint ep = e.Argument as IPEndPoint;
TcpListenerEx listener = new TcpListenerEx(ep);
if (!listener.Active)
{
listener.Start();
}
while (true)
{
try
{
const int byteSize = 1024 * 1024;
byte[] message = new byte[byteSize];
using (var s = listener.AcceptTcpClient())
{
s.GetStream().Read(message, 0, byteSize);//obtaining network stream and receiving data through .Read()
message = cleanMessage(message);
string g = System.Text.Encoding.UTF8.GetString(message);
backgroundWorker1.ReportProgress(0, g);
}
}
catch (Exception ex)
{
backgroundWorker1.ReportProgress(0, ex.Message);
}
finally
{
listener.Stop();
}
}
}
private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
textBox1.AppendText(Environment.NewLine + ">> " + e.UserState);
}
private byte[] cleanMessage(byte[] rawMessageByte)
{
byte[] cleanMessage = rawMessageByte.Where(b => b != 0).ToArray();
return cleanMessage;
}
}
}
Hope it helps.
I'm trying to write a remote control application to Windows Phone 7.
All goes OK, but i can not make IP scan over net.
Connected param in Socket class works badly. To use it i need to connect to any IP, then send anymessage - it's Ok. But timeout is too long - about 10 secs(for turned off Pcs).
I need to scan about 256 IPs, and 2560 seconds - is too long.
I tried to write timeout by my self. It works, but after some time application stops.
I can not understand why. No exceptions. Phone just stops attempts to connect and visual studio crashes sometimes.
If there is overflow - where can it be?
Here is some code:
(TryHost is runnung in FOR cycle. Only one start at a time, Searcher.AddHost() runs next iteration of TryHost)
AsynchronousClient:
public void TryHost(string host)
{
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
DnsEndPoint hostEntry = new DnsEndPoint(host, _port);
// Create a socket and connect to the server
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(SocketEventArg_Completed1);
socketEventArg.RemoteEndPoint = hostEntry;
sock.NoDelay = true;
socketEventArg.UserToken = sock;
try
{
sock.ConnectAsync(socketEventArg);
}
catch (SocketException ex)
{}
}
void SocketEventArg_Completed1(object sender, SocketAsyncEventArgs e)
{
switch (e.LastOperation)
{
case SocketAsyncOperation.Connect:
ProcessConnect1(e);
break;
case SocketAsyncOperation.SendTo:
connected = false;
ProcessSend1(e);
break;
case SocketAsyncOperation.Receive:
sended = false;
ProcessReceive1(e);
break;
default:
throw new Exception("Problems");
}
}
private void ProcessReceive1(SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
// Received data from server
string dataFromServer = Encoding.UTF8.GetString(e.Buffer, 0, e.BytesTransferred);
if (dataFromServer.IndexOf("<EOF>") > -1)
{
Searcher.AddHost(dataFromServer);
}
}
else
{
Searcher.AddHost(null);
}
}
private void ProcessSend1(SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
Socket sock = e.UserToken as Socket;
sended = true;
sock.ReceiveAsync(e);
Thread.Sleep(500);
if (sended)
{
sock.Dispose();
Searcher.AddHost(null);
}
}
else
{
Searcher.AddHost(null);
}
}
private void ProcessConnect1(SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
byte[] buffer = Encoding.UTF8.GetBytes("Knock" + "!" + sessionId + "<EOF>");
e.SetBuffer(buffer, 0, buffer.Length);
sock = e.UserToken as Socket;
connected = true;
sock.SendToAsync(e);
e.ConnectSocket.NoDelay = false;
Thread.Sleep(500);
if (connected)
{
sock.Dispose();
}
}
else
{
sock.Dispose();
Searcher.AddHost(null);
}
}
i'm using static class Searcher. UI button starts search from StartSearch() metod wich prepares class to search, and run methods in AsyncClient variable. When AssyncClient request is timed out or answered by host, AssyncClient runs AddHost() method
and Searcher prepares next IP, then start TryHost() again
static Searcher:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Threading;
namespace PivotApp1 {
class PartedIp
{
public string FirstPart;
public string LastPart;
public PartedIp(string first, string last)
{
FirstPart = first;
LastPart = last;
}
}
public class SearchArgs : EventArgs
{
private List<string> message;
public SearchArgs(List<string> msg)
{
message = msg;
}
public List<string> Message
{
get { return message; }
}
}
public static class Searcher
{
static bool searching = false;
static string phoneIp = "";
static string ipTemplate = "";
static int currentLookingIp;
static int stopIp;
static List<string> answers = new List<string>();
static AsynchronousClient newC;
static int chBound = 255;
static int lwBound = 255;
public static event EventHandler SearchComplete = delegate { };
public static void SayItsOver(List<string> message)
{
SearchComplete(null, new SearchArgs(message));
}
static AsynchronousClient searcher;
static string CheckIp()
{
string phoneIp = null;
try
{
MyIPAddress finder = new MyIPAddress();
finder.Find((address) =>
{
phoneIp = address == null ? "Unknown" : address.ToString();
});
}
catch (Exception e)
{
throw new Exception();
}
if (phoneIp == "Unknown")
{
return null;
}
else
{
return phoneIp;
}
}
static PartedIp PrepareForSearch(string phoneIp)
{
IPAddress ipForTest = new IPAddress(10);
if (IPAddress.TryParse(phoneIp, out ipForTest))
{
string[] splittedIp = phoneIp.Split('.');
PartedIp phonePartedIp = new PartedIp(splittedIp[0] + '.' + splittedIp[1] + '.' + splittedIp[2] + '.', splittedIp[3]);
return phonePartedIp;
}
else return null;
}
public static void StartSearch(AsynchronousClient newC)
{
phoneIp = CheckIp();
if (phoneIp != null)
{
searching = true;
newC = newC1;
PartedIp partedIp = PrepareForSearch(phoneIp);
ipTemplate = partedIp.FirstPart;
stopIp = Int32.Parse(partedIp.LastPart);
currentLookingIp = stopIp - 1;
newC.TryHost(ipTemplate + currentLookingIp);
}
else
Deployment.Current.Dispatcher.BeginInvoke(() => {
MessageBox.Show("Error in Ip detection");
});
}
static void NextHost()
{
if (searching)
{
currentLookingIp--;
if (currentLookingIp == 0)
currentLookingIp = 255;
}
}
static public void AddHost(string answer)
{
if (searching)
{
if (answer != null)
{
answers.Add(answer);
}
NextHost();
if (currentLookingIp == stopIp)
{
SayItsOver(answers);
searching = false;
}
else
{
newC.TryHost(ipTemplate + currentLookingIp);
}
}
}
} }
I debugged this a lot of time. My start ip = 192.168.0.103. My Server Ip = 192.168.0.100.
Search working perfectly, until 192.168.0.19(no PCs here). Even if i start my search from 192.168.0.20 it crashed.
Another dead zone is 192.168.0.1 and next 192.168.0.255.
Also - manual starting of TryHost() works fine. Problems begin when I'm trying to automate search.
What's wrong?
I spent a few days on it and just do not know what to do.