fclose(obj) does not work immediately
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Image Analyst
2022-4-24
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 个评论
SrinivasHarsha
2022-4-26
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
2022-4-26
Image Analyst does not volunteer email support. He will not help you through email.
Walter Roberson
2022-4-25
编辑:Walter Roberson
2022-4-27
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!