Skip to content

Commit 605ff44

Browse files
authored
Merge pull request #127 from anecdata/udp_client
UDP Client using socket
2 parents 2648133 + f1175ae commit 605ff44

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def set_interface(iface):
2727
_the_interface = iface
2828

2929

30-
SOCK_STREAM = const(1)
30+
SOCK_STREAM = const(0)
31+
SOCK_DGRAM = const(1)
3132
AF_INET = const(2)
3233
NO_SOCKET_AVAIL = const(255)
3334

@@ -56,8 +57,7 @@ def __init__(
5657
):
5758
if family != AF_INET:
5859
raise RuntimeError("Only AF_INET family supported")
59-
if type != SOCK_STREAM:
60-
raise RuntimeError("Only SOCK_STREAM type supported")
60+
self._type = type
6161
self._buffer = b""
6262
self._socknum = socknum if socknum else _the_interface.get_socket()
6363
self.settimeout(0)
@@ -78,8 +78,12 @@ def connect(self, address, conntype=None):
7878
self._buffer = b""
7979

8080
def send(self, data): # pylint: disable=no-self-use
81-
"""Send some data to the socket"""
82-
_the_interface.socket_write(self._socknum, data)
81+
"""Send some data to the socket."""
82+
if self._type is SOCK_DGRAM:
83+
conntype = _the_interface.UDP_MODE
84+
else:
85+
conntype = _the_interface.TCP_MODE
86+
_the_interface.socket_write(self._socknum, data, conn_mode=conntype)
8387
gc.collect()
8488

8589
def write(self, data):

0 commit comments

Comments
 (0)