Thread.Sleep()
-
Hi I have used multithreading for udp client/server communication.When i run the server both the threads are executing at the same time.So i used a Thread.Sleep() after the 1st thread.So the 1st thread works properly.When it comes to the 2nd thread it gives"the existing connection was forcibly closed by the remote host".Can you please give me your suggestion
-
Hi I have used multithreading for udp client/server communication.When i run the server both the threads are executing at the same time.So i used a Thread.Sleep() after the 1st thread.So the 1st thread works properly.When it comes to the 2nd thread it gives"the existing connection was forcibly closed by the remote host".Can you please give me your suggestion
-
is it because thread 2 is being called from in thread 1? it would be better if you could post some example code
Life goes very fast. Tomorrow, today is already yesterday.
Please give me your suggestion asap
public UdpServer()
{
try
{
startServer = new Thread(new ThreadStart(start_server));
startServer.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
//startServer.Abort();
}Thread.Sleep(20000); try { startServer2 = new Thread(new ThreadStart(start\_server2)); startServer2.Start(); } catch (Exception e) { Console.WriteLine(e.Message); //startServer2.Abort(); } } public static void start\_server() { IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001); try { Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); newsock.Bind(ipep); Console.WriteLine("Waiting for a client..."); while (true) { //IPEndPoint sender = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8050); EndPoint tmpRemote = (EndPoint)ipep; // EndPoint tmpRemote = (sender); byte\[\] data = new byte\[1024\]; Console.WriteLine("hai"); int recv = newsock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote); Console.WriteLine("Message received from {0}:", tmpRemote.ToString()); Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));//hello is received data = new byte\[1024\]; string ss = "Welcome to the Server"; data = Encoding.ASCII.GetBytes(ss); newsock.SendTo(data, 0, data.Length, SocketFlags.None, tmpRemote); Console.WriteLine("\\nSent Acknowledgement"); } } catch (SocketException e) { Console.WriteLine(e.Message); } //start\_server(); //startServer.Start(); }
public static void start_
-
Please give me your suggestion asap
public UdpServer()
{
try
{
startServer = new Thread(new ThreadStart(start_server));
startServer.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
//startServer.Abort();
}Thread.Sleep(20000); try { startServer2 = new Thread(new ThreadStart(start\_server2)); startServer2.Start(); } catch (Exception e) { Console.WriteLine(e.Message); //startServer2.Abort(); } } public static void start\_server() { IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001); try { Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); newsock.Bind(ipep); Console.WriteLine("Waiting for a client..."); while (true) { //IPEndPoint sender = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8050); EndPoint tmpRemote = (EndPoint)ipep; // EndPoint tmpRemote = (sender); byte\[\] data = new byte\[1024\]; Console.WriteLine("hai"); int recv = newsock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote); Console.WriteLine("Message received from {0}:", tmpRemote.ToString()); Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));//hello is received data = new byte\[1024\]; string ss = "Welcome to the Server"; data = Encoding.ASCII.GetBytes(ss); newsock.SendTo(data, 0, data.Length, SocketFlags.None, tmpRemote); Console.WriteLine("\\nSent Acknowledgement"); } } catch (SocketException e) { Console.WriteLine(e.Message); } //start\_server(); //startServer.Start(); }
public static void start_
-
Please give me your suggestion asap
public UdpServer()
{
try
{
startServer = new Thread(new ThreadStart(start_server));
startServer.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
//startServer.Abort();
}Thread.Sleep(20000); try { startServer2 = new Thread(new ThreadStart(start\_server2)); startServer2.Start(); } catch (Exception e) { Console.WriteLine(e.Message); //startServer2.Abort(); } } public static void start\_server() { IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001); try { Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); newsock.Bind(ipep); Console.WriteLine("Waiting for a client..."); while (true) { //IPEndPoint sender = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8050); EndPoint tmpRemote = (EndPoint)ipep; // EndPoint tmpRemote = (sender); byte\[\] data = new byte\[1024\]; Console.WriteLine("hai"); int recv = newsock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote); Console.WriteLine("Message received from {0}:", tmpRemote.ToString()); Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));//hello is received data = new byte\[1024\]; string ss = "Welcome to the Server"; data = Encoding.ASCII.GetBytes(ss); newsock.SendTo(data, 0, data.Length, SocketFlags.None, tmpRemote); Console.WriteLine("\\nSent Acknowledgement"); } } catch (SocketException e) { Console.WriteLine(e.Message); } //start\_server(); //startServer.Start(); }
public static void start_
Sorry i didnt read the exception in your OP. That exception says that there is a problem with the host you are connected to. i.e. the server. This means the server is cancelling the connection for one reason or another, it could be your server is limiting connections to just one (your first thread) and thats why the second fails. I cant help much with this kind of thing, but you basically need to look at settings on your server somewhere.
Life goes very fast. Tomorrow, today is already yesterday.