refer to: http://www.mathworks.com/matlabcentral/fileexchange/21131-tcp-ip-socket-communications-in-matlab
And: http://cn.mathworks.com/help/instrument/creating-a-tcpip-object.html
Session 1: MATLAB Server
Accept a connection from any machine on port 30000.
t = tcpip('0.0.0.0', 30000, 'NetworkRole', 'server');
Open a connection. This will not return until a connection is received.
fopen(t);
Read the waveform and confirm it visually by plotting it.
data = fread(t, t.BytesAvailable); plot(data);
Session 2: MATLAB Client
This code is running on a second copy of MATLAB.
Create a waveform and visualize it.
data = sin(1:64); plot(data);
Create a client interface and open it.
t = tcpip('localhost', 30000, 'NetworkRole', 'client');
fopen(t)
Write the waveform to the server session.
fwrite(t, data)
本文介绍了一个使用 MATLAB 进行 TCP/IP 通信的示例,包括服务器端和客户端的实现。服务器监听 30000 端口接收连接请求,并读取从客户端发送过来的正弦波数据;客户端创建正弦波形并将其发送给服务器。
38万+

被折叠的 条评论
为什么被折叠?



