End Google Ads 201810 - BS.net 01 --> Hi
I have used the following code for the client server communication.The start() starts the server and calls the SenMessage() to send the message to the server.This method takes as input the port number of the server that has started.

It works fine.Suppose i start 2 servers, then both servers are calling the SendMessage().In this case one server communicates properly.For the 2nd one it says that the existing connection is closed.

I think that when the 2nd server starts it should call the sendMessage() with some time delay.I hope that it work then.But im not sure how to do it.Please help me with this.private void Start_Click(object sender, EventArgs e)
{
//int n;
//label1.Text = "Enter the value of n:";
String n2, n1, n3, n4;
n1 = lb4.Text;
n2 = lb5.Text;
n3 = lb6.Text;
n4 = lb7.Text;
ProcessStartInfo si1,si2,si3,si4;

if (cb.Checked && lb4.Text!="")
{

si1 = new ProcessStartInfo(n1);
proc = Process.Start(si1);
proclist.Add(proc);
String portno1 = n1.Substring(18, 5);
listBox1.Items.Add(portno1);
pno1=Convert.ToInt32(portno1);
SendMessage(pno1);
}
if (cb1.Checked && lb5.Text!="")
{
n2 = lb5.Text;
si2 = new ProcessStartInfo(n2);
proc = Process.Start(si2);
proclist.Add(proc);

String portno2 = n2.Substring(18, 5);
int pno2 = Convert.ToInt32(portno2);
SendMessage(pno2);
}
}

public void SendMessage(int portnumber)
{

try
{
UdpClient client = new UdpClient("127.0.0.1", portnumber);
listBox2.Items.Add("Connected");
Byte[] data = new Byte[256];
String snd = "hello";
data = Encoding.ASCII.GetBytes(snd);
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), portnumber);
int n = client.Send(data, data.Length);
listBox2.Items.Add("Sent...");
listBox2.Items.Add("Message received from {0}:");
listBox2.Items.Add(ipep.ToString());
Byte[] received = new Byte[512];
received = client.Receive(ref ipep);
String dataReceived = System.Text.Encoding.ASCII.GetString(received);
listBox2.Items.Add(dataReceived);

client.Close();

//}
}
catch (Exception e)
{
listBox2.Items.Add("An Exception Occurred!");
listBox2.Items.Add(e.ToString());
}


}