aboutsummaryrefslogtreecommitdiffstats
path: root/src/net.py
diff options
context:
space:
mode:
authorsara <sara.halter@gmx.ch>2021-11-17 17:24:29 +0100
committersara <sara.halter@gmx.ch>2021-11-17 17:24:29 +0100
commit1dadaa301589c5ddf4b2a8e3c4675bf812bd1601 (patch)
tree917a0c68860a3da0e68c9a1ce146c11ed34b3c9a /src/net.py
parentDoku weitergeschriben/angepasst (diff)
parentReplace GNURadio scripts with network code (diff)
downloadFading-1dadaa301589c5ddf4b2a8e3c4675bf812bd1601.tar.gz
Fading-1dadaa301589c5ddf4b2a8e3c4675bf812bd1601.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/net.py')
-rw-r--r--src/net.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/net.py b/src/net.py
new file mode 100644
index 0000000..6bd71ac
--- /dev/null
+++ b/src/net.py
@@ -0,0 +1,33 @@
+import select
+import socket
+from urllib.parse import urlparse
+
+import numpy as np
+
+
+class udpsource:
+ """
+ Creates an UDP listening socket
+ """
+ def __init__(self, url):
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ self.url = urlparse(url)
+
+ def __del__(self):
+ self.sock.close()
+
+ def bind(self):
+ self.sock.setblocking(False)
+ self.sock.bind((self.url.hostname, self.url.port))
+ # self.sock.listen()
+
+ def read(self, nbytes):
+ ready_to_read, ready_to_write, in_err = \
+ select.select([self.sock], [], [], 1)
+
+ if ready_to_read:
+ data = sock.recv(nbytes)
+ print(data)
+ else:
+ return None
+