필터 지우기
필터 지우기

How to address server and multiple clients communicate using tcpip function?

조회 수: 6 (최근 30일)
t = tcpip(0.0.0.0,3000,'NetworkRole','server');
fopent(t) --server is open for connection
t = tcpip('localhost',3000,'NetworkRole','client');
fopent(t) --client connects to server from other instance of matlab
But, only one client is able to connect, how can we make multiple instances to connect with server?

답변 (2개)

Walter Roberson
Walter Roberson 2018년 3월 26일
You would need to call
t = tcpip(0.0.0.0,3000,'NetworkRole','server');
multiple times, once for each client.
Unfortunately there does not appear to be a timeout for the fopen() property of tcpip objects, and the fopen() is blocking, so you do not appear to be easily use the strategy of running a new tcpip/fopen with timeout after a successful fopen() in order to wait for potential new clients.
This suggests to me that the approach would have to be something along the lines of using parfeval() to create a future as the future can afford to sit around and wait while everything else goes on. I am not certain but this might limit the number of clients according to the size of your parpool.
To deal with communications between the future and the main work to be done, you might want to use parallel.pool.PollableDataQueue, using one in each direction for each future (each of them is unidirectional.)
I do not say that these are good ways to handle multiple clients, but keep in mind that MATLAB itself is single threaded.
... I suspect you might find it a lot smoother to use Java to create the sockets.

Kiran Satish
Kiran Satish 2019년 12월 6일
I have a similar question, as per my understanding, a socket opened as a server, should remain active until it is closed no matter how many times a client connects and disconnects to it. Isnt it not the case with tcpip objects defined as server in matlab? For me, i have to reopen the server port everytime I disconnect a client (another tcpip object defined as client on another system). Any suggestions why it is like that, I would like to keep server object active as long as I keep it open irrespective of client connect & disconnects. I am tlaking about only one client here.
thanks
  댓글 수: 3
Kiran Satish
Kiran Satish 2019년 12월 6일
Thanks Walter for your reply. I know one can use UDP to have a open connection all the time, I have a version of my applications based on UDP. For now, the requirement is for TCPIP, will check on your suggestions on SO_REUSE etc.
Walter Roberson
Walter Roberson 2019년 12월 6일
I don't think you can set these using MATLAB's tcpip() . They are more things to know if you use Java to construct the sockets.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by