I'm facing a problem of stop the socket.connect() function. Sometimes the physical link between my local machine and the remote machine might be good, but due to some reason, the remote endpoint cannot be accessed, maybe a firewall or the port on the remote machine is closed. In such cases, the socket.connection() function will be stuck there and waits for an infinite long time...Even the firewall is disabled later, the function will still stuck there forever.
So I tried to find a way to stop the socket.connect() when faces the above situations.
The thing is I'm using a .net micro framework in which I dont have timeout mechanism or task or socket.beginconnect();
I'm trying making the socket.connect() itself a thread and tried to abort() it after 2 seconds if (!thread.join(2000)). However, I dont quite understand the abort() function and i've heard its an unwise way to do so and it does not work afterall.
Now i dont know what to do about it? can anyone help? thx a lot
main function
{
m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//Set up socket
remoteEndPoint = new IPEndPoint(IPAddress.Parse(IP_add), 30000);
m_socket.Connect(remoteEndPoint);
myThread.Start();
if (!myThread.Join(2000))
{
Debug.Print(myThread.ThreadState.ToString());
myThread.abort();
}
}
private static void socket_connect()
{
m_socket.Connect(remoteEndPoint);//Connect to remote device
}