Hi,
I'm running FlightGear simulation software and output some variable data through UDP on the loopback address 127.0.0.1, port 1234. Using the SocketTest application I can see the data being received however I would like to do this through Matlab which is running on the same PC.
I try to run the following:
while(1)
u = udp('localhost',1234,'localport',1234);
u.InputBufferSize = 1000;
u.DatagramReceivedFcn = @localReadDatagram;
fopen(u);
end
My issue is that I always get the error: "Unsuccessful open: Address already in use: Cannot bind ", can anyone help?
Thanks, Joe

 채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 31일

0 개 추천

You should probably use a different localport unless the receiving software insists that the transmitting port be 1234 . localport is the port number that data is transmitted from.

댓글 수: 4

Joe Fleming
Joe Fleming 2016년 10월 31일
편집: Joe Fleming 2016년 10월 31일
Ok so changing the Flightgear port to 5000 and then changing my Matlab code to:
while(1)
u = udp('localhost',5001,'localport',5000);
u.InputBufferSize = 1000;
u.DatagramReceivedFcn = @localReadDatagram;
fopen(u);
end
I now get the following error:
Error using icinterface/fopen (line 83)
Unsuccessful open: Address already in use: Cannot bind
Error in UDP_Connection (line 6)
fopen(u);
Undefined function or variable 'localReadDatagram'.
Error in instrcb (line 36)
feval(val{1}, obj, eventStruct, val{2:end});
Warning: The DatagramReceivedFcn is being disabled. To enable the callback property
either connect to the hardware with FOPEN or set the DatagramReceivedFcn property.
Walter Roberson
Walter Roberson 2016년 10월 31일
Ah, the problem is that you are doing the open in a loop. You should only open once, and then make sure that u does not go out of scope while you use it. Remember to close it after you are done.
Ok so I've removed the code from a while loop and I'll just close it through the command window manually for now. Socket test shows the address as 127.0.0.1:52867, so I've set the the ports to the following, is that correct?
u = udp('localhost',52867,'localport',5000);
u.InputBufferSize = 1000;
u.DatagramReceivedFcn = @localReadDatagram;
fopen(u);
I now get the error:
Undefined function or variable 'localReadDatagram'.
Error in instrcb (line 36)
feval(val{1}, obj, eventStruct, val{2:end});
Joe Fleming
Joe Fleming 2016년 10월 31일
All sorted - Thanks for your help

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Flight Simulator Interfaces에 대해 자세히 알아보기

질문:

2016년 10월 31일

댓글:

2016년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by