How can i send data in using "UDP" Command?

3 次查看(过去 30 天)
I wanted to send data in network .Firstly ,I have loaded file name as "target.dat" .
this is the code i used to send data.
HOST1 = '192.168.3.13';
SOURCE_PORT1 = 4038;
LOCAL_PORT1 = 1020;
Buffer_size1 = 50000;
u1 = udp(HOST1, SOURCE_PORT1,'Localport' ,LOCAL_PORT1);
set(u1,'inputBufferSize',Buffer_size1);
set(u1,'outputBufferSize',Buffer_size1);
fopen(u1);
flushinput(u1); %flusing i/p o/p buffers
flushoutput(u1);
disp("sent")
its showing error as:
"Unsuccessful open: Address already in use: Cannot bind"
Please, help me out sloving this error.
I restarted matlab application also, still same same error is appearing.

回答(1 个)

Koundinya
Koundinya 2019-5-29
Like the error message mentions, the port is already being used by another application ( or by an earlier run of your MATLAB script) . You might need to first restart your machine to free up the port ( or kill the process that is listening on that port).
You can enable port sharing to allow multiple UDP sockets to bind to the port :
u1 = udp(HOST1, SOURCE_PORT1,'Localport' ,LOCAL_PORT1);
u1.EnablePortSharing = 'on';
Also make sure to close the UDP socket at the end to avoid running into such problems :
fclose(u1);

类别

Help CenterFile Exchange 中查找有关 Development Computer Setup 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by