UDP
A UDP channel isn't connected to one outstation, so each association on it also needs the outstation's address and port. Create the channel with the local address and port it listens on, then add each association with its remote endpoint:
- Rust
- C
- C++
- Java
- C#
let channel = spawn_master_udp(
local_endpoint,
LinkReadMode::Datagram,
Timeout::from_secs(5)?,
get_master_channel_config(master_address)?,
);
let association = channel
.add_udp_association(
outstation_address,
remote_endpoint,
get_association_config(),
Box::new(ExampleReadHandler),
Box::new(ExampleAssociationHandler),
Box::new(ExampleAssociationInformation),
)
.await?;
dnp3_master_channel_t *channel = NULL;
dnp3_param_error_t err = dnp3_master_channel_create_udp(
runtime,
get_master_channel_config(),
local_endpoint,
DNP3_LINK_READ_MODE_DATAGRAM,
5000, // retry binding the socket every 5 seconds
&channel
);
dnp3_param_error_t err = dnp3_master_channel_add_udp_association(
channel,
OUTSTATION_ADDRESS,
remote_endpoint,
get_association_config(),
get_read_handler(),
get_association_handler(),
get_association_information(),
association_id
);
auto channel = dnp3::MasterChannel::create_udp_channel(
runtime,
get_master_channel_config(),
local_endpoint,
dnp3::LinkReadMode::datagram,
std::chrono::seconds(5) // retry binding the socket every 5 seconds
);
auto assoc = channel.add_udp_association(
OUTSTATION_ADDRESS,
remote_endpoint,
get_association_config(),
create_read_handler(),
create_association_handler(),
create_association_information()
);
MasterChannel channel =
MasterChannel.createUdpChannel(
runtime,
getMasterChannelConfig(),
UDP_LOCAL_ENDPOINT,
LinkReadMode.DATAGRAM,
Duration.ofSeconds(5)
);
AssociationId association =
channel.addUdpAssociation(
ushort(OUTSTATION_ADDRESS),
remoteEndpoint,
getAssociationConfig(),
new ExampleReadHandler(),
new ExampleAssociationHandler(),
new ExampleAssociationInformation());
var channel = MasterChannel.CreateUdpChannel(
runtime,
GetMasterChannelConfig(),
UdpLocalEndpoint,
LinkReadMode.Datagram,
TimeSpan.FromSeconds(5)
);
var association = channel.AddUdpAssociation(
OutstationAddress,
remoteEndpoint,
GetAssociationConfig(),
new ExampleReadHandler(),
new ExampleAssociationHandler(),
new ExampleAssociationInformation()
);