Skip to content

Commit 07b3797

Browse files
gdsportsfpistm
authored andcommitted
Use UDP unconnected sockets
UDP connected sockets are limited to commuinicating with one host and port.
1 parent 5f6c5b6 commit 07b3797

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/EthernetUdp.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ int EthernetUDP::beginPacket(IPAddress ip, uint16_t port)
106106

107107
ip_addr_t ipaddr;
108108

109-
if(ERR_OK != udp_connect( _udp.pcb, u8_to_ip_addr(rawIPAddress(ip), &ipaddr), port)) {
110-
return 0;
111-
}
109+
_sendtoIP = ip;
110+
_sendtoPort = port;
112111

113112
udp_recv(_udp.pcb, &udp_receive_callback, &_udp);
114113
stm32_eth_scheduler();
@@ -122,12 +121,8 @@ int EthernetUDP::endPacket()
122121
return 0;
123122
}
124123

125-
// A remote IP & port must be connected to udp pcb. Call ::beginPacket before.
126-
if((udp_flags(_udp.pcb) & UDP_FLAGS_CONNECTED) != UDP_FLAGS_CONNECTED) {
127-
return 0;
128-
}
129-
130-
if(ERR_OK != udp_send(_udp.pcb, _data)) {
124+
ip_addr_t ipaddr;
125+
if(ERR_OK != udp_sendto(_udp.pcb, _data, u8_to_ip_addr(rawIPAddress(_sendtoIP), &ipaddr), _sendtoPort)) {
131126
_data = stm32_free_data(_data);
132127
return 0;
133128
}

src/EthernetUdp.h

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class EthernetUDP : public UDP {
5050
uint16_t _port; // local port to listen on
5151
IPAddress _remoteIP; // remote IP address for the incoming packet whilst it's being processed
5252
uint16_t _remotePort; // remote port for the incoming packet whilst it's being processed
53+
IPAddress _sendtoIP; // the remote IP address set by beginPacket
54+
uint16_t _sendtoPort; // the remote port set by beginPacket
5355

5456
struct pbuf *_data; //pbuf for data to send
5557
struct udp_struct _udp; //udp settings

0 commit comments

Comments
 (0)