fclose(obj) does not work immediately
6 views (last 30 days)
Show older comments
I have a TCPIP conncetion and I send and read data with an app designer application.
I use fclose(obj) function, but the tcp connection does not close immediately and it takes one or two minutes until it is closed.
after I close the connection I want to reopen it and I get this error:
Unsuccessful open: Address already in use:
connect
0 Comments
Answers (2)
Image Analyst
on 24 Apr 2022
In the help for tcpclient() and fclose(), I don't see any mention of using fclose() to close a tcp session. It says this:
Close the connection between the TCP/IP client and the remote host by clearing the object. Turn off the echotcpip server.
clear t
echotcpip("off")
You might also call flush() before closing just to see if that speeds anything up.
7 Comments
SrinivasHarsha
on 26 Apr 2022
Hi Image Analyst,
we need a help from you
can you send a response to my mail if possible.
we will contact you reg: image processing help
my mail id: srinivas.nato@gmail.com
Walter Roberson
on 26 Apr 2022
Image Analyst does not volunteer email support. He will not help you through email.
Walter Roberson
on 25 Apr 2022
Edited: Walter Roberson
on 27 Apr 2022
When you use tcp the default keep-alive timeout is 2 hours https://docs.microsoft.com/en-us/windows/win32/winsock/so-keepalive . When you close a socket it can take until the end of that interval before the system clears the connection.
This is an inherently hard problem in reliable asynchronous communications.
When your end says Bye, how do you know that the other end heard you so that you can remove the local resources? Well, you can require that the other end sends you a response. Can the other end clear their state immediately after sending the response? Well, how does the other end know that your end received the response? So your end has to send a response to the response. But how does your end know that the other end heard the response to the response? It has to send a response to that....
If you go through the logic, it turns out that for reliable service, you need an indefinite chain of acknowledgement of acknowledgement. So in practice you need a timeout system. If your end does not receive the last packet in the shutdown sequence but the other end has already removed the state then you might need to wait through the timeout period. This is not a MATLAB issue: it happens for all reliable asynchronous communications protocols.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!