Hi to all,
I have 5Clientsin the network for eachClienthaving unique IP Address if i connect for eachClientand disconnect ,no problem.
my problem is if one of the Client not connected to network that time its show error connecting. the reminingClientsfailed to connection.
why its happning how can i reset socket connection when its fail.
void ButtonConnectOnClick(object obj, EventArgs ea)
{
foreach (DataRow row inClients.Tables[0].Rows)
{
Ip_Address = row["IP_Address"].ToString().ToUpper();
Port_No = (int)row["PortNo"];
conStatus.Text = "Connecting...";
Socket newsock = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(Ip_Address), Port_No);
newsock.BeginConnect(iep, new AsyncCallback(Connected), newsock);
}
}
void Connected(IAsyncResult iar)
{
client = (Socket)iar.AsyncState;
try
{
client.EndConnect(iar);
conStatus.Text = "Connected to: " + client.RemoteEndPoint.ToString();
client.BeginReceive(data, 0, size, SocketFlags.None,
new AsyncCallback(ReceiveData), client);
}
catch (SocketException)
{
conStatus.Text = "Error connecting";
}
}
ak