Hi , I'm working on a project in matlab
I have a matlab GUI on one computer and I want to send a word indicating which button on the GUI has been clicked to the other computer using UDP where the 2nd computer can execute specific function later on according to the button clicked ,
my problem is that I can only click one button that the computer on the other side will receive its data & then I have to re run the server side again to revive the 2nd button clicked .. my UDP connection on the server side will end just accepts one data
how can I make it accepts more the one until I end it my self ?
here what I'm doing :
PC 1
u1 = udp('192.168.1.2', 'RemotePort', 8866, 'LocalPort', 8844) fopen(u1) fprintf(u1,'counter clk wise') fclose(u1) delete(u1) clear u1
This will be repeated with every button I couldn't make it general in the GUI
& here my server PC2 :
u2 = udp('192.168.1.2', 'RemotePort', 8844, 'LocalPort', 8866) fopen(u2) % open the host 2 pause(1) fscanf(u2) % print data from host 1 % close : %fclose(u2)
I've read several topics but no luck ... can any one help me with this a hint maybe
thnx

 채택된 답변

Rob Graessle
Rob Graessle 2011년 10월 28일

1 개 추천

To receive multiple messages, you need to put a loop in the PC2 code. Something like this:
u2 = udp('192.168.1.2', 'RemotePort', 8844, 'LocalPort', 8866)
fopen(u2) % open the host 2
while ~<insert some stopping condition here>
pause(1)
fscanf(u2) % print data from host 1
end
fclose(u2)

댓글 수: 4

wafa isa
wafa isa 2011년 10월 29일
Thank u so much for the help
it's working now =D
thanks much appreciate ur help
Assad
Assad 2012년 2월 10일
i am using the above code and its not working it is giving me error that
????Error using==>icinterface.fopen at 83
unrecognized Windows Socket error 0:cannot bind
error in ==>pc2 at 2
fopen(u2)
i am running the above code as
u2 = udp('192.168.0.100', 'RemotePort', 8888, 'LocalPort', 8888)
fopen(u2) % open the host 2
while ~<insert some stopping condition here>
pause(1)
fscanf(u2) % print data from host 1
end
fclose(u2)
this is the error in PC 2
Justin Liang
Justin Liang 2013년 6월 1일
I get that error as well, no sure why.
Walter Roberson
Walter Roberson 2013년 6월 1일
Possibly the port is already in use.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2011년 10월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by