Problems With Exceptions and Sockets

May 22 2005 1:58 PM
I want to implement a TCP Listener wich Listens for 1 min if there is no connection pending i want to restart the whole process of creating the listener, this is because i'm implementing a state machine. try { do { retry = false; char[] mensaje = SMS.BuildMessageforRemota(name,destnum, port); //SMS.SendMessage(mensaje); //Making the TCPListener to Listen MyListener.Start(); myTimer.Change(0, 60000); Server(MyListener.AcceptSocket()); //if this is succesfully a blocking call then program flow //will be hold here until i have someone that has connected //or the Timer Stops the Listener } while (retry && attempts < 3); the routine wich is called by my timer: public void ResetConnectionAttemp(Object State) { attempts++; //increase the amount of attempts retry = true; if (MyListener != null) { MyListener.Stop(); } } now, when i call MyListener.Stop(), i get a SocketException because i make an unblocking call to the BlockingCall made by MyListener.AcceptSocket(), is there a way to avoid this exception, because this is exactly what i want to make, hold the program execution for 1 min, then stop it, and resend the SMS to wakeup whoever is going to connect with me,(if it doesn't works the first time, is because the message didn't arrive, that's why i need to resend it), another option is, is there a possibility to make a timeout for the listener, wich will close the connection by itself without throwing the exception without the Timer class?? thanks!!!

Answers (4)