MATLAB Answers

Timeout when running tcpip in server mode OR how to force fopen to return after a set timeout

25 ビュー (過去 30 日間)
D. Plotnick
D. Plotnick 2019 年 7 月 29 日
Hello all,
I found and was playing with Matlab's ability to act as tcpip server:
t = tcpip('localhost',30000,'NetworkRole','server')
fopen(t)
I can then use this connection to send files between Matlab instances (such as me and my lab mate). However, fopen does not return until a connection has been made by someone. While I can ctrl-C to get out of this, you cannot ctrl-C in a deployed application AND this drops us out of the entire program rather than letting us skip this step and move on with other operations. Nominally I would want a connection timeout option for the tcpip object, but there is no such property or method.
So, I can see 3 possible options,
  • Run fopen asynchronously so that even if it is sitting there waiting till the dawn of time, the rest of my code can continue to execute.
  • Run fopen with some sort of timeout enforced externally during the call (something like FEX timeout, but not using ctrl-C. I just want to force the fopen command to return after a reasonable period).
  • Modify tcpip itself to allow for a timeout.
The middle is my favorite, since I can use that for other code. Any ideas?
-DP

  1 件のコメント

Darshan Vijayaraghavan
Darshan Vijayaraghavan 2020 年 6 月 4 日
Can you explain on how or elaborate more on the 2nd point that you mentioned above?

サインインしてコメントする。

回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by