TCP/IP connection is very slow when using fscanf to read from other computer

6 ビュー (過去 30 日間)
GAURAV PATHAK
GAURAV PATHAK 2015 年 9 月 25 日
コメント済み: dace su 2021 年 7 月 28 日
Hello, I make a connection to other operating system and send the data using fprintf and recieve using fscanf. Below is code for all- It is running perfectly fine but while receiving it is very slow. It wait for around 6-10 sec and then receive the data. How can I make it fast. My data is not big.
t2 = tcpip('192.168.56.101', 8001, 'NetworkRole', 'client');
set(t2, 'InputBufferSize', 30000);
fopen(t2);
fprintf(t2,'%5.4f,%5.4f,%5.4f,%5.4f',B(:));
pause(0.1);
while (get(t2, 'BytesAvailable') > 0)
DataReceived = fscanf(t2,'%c')
end
fclose(t2);
delete(t2);
clear t2;
Can you help me out how to make it fast as my data is not big.
Thanks
  1 件のコメント
dace su
dace su 2021 年 7 月 28 日
Hello, have you solved this problem? I meet the same problem with you.

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

回答 (1 件)

JangHo Cho
JangHo Cho 2015 年 10 月 2 日
In my case, I use fwrite and fread instead of fprintf and fscanf.
Sending site :
A = [1 3 4 2 5 7];
fwrite(t, A, 'float64');
Receiving site :
A = fread(t, 6, 'float64');

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by