I have a device that converts analog audio to digital audio, and there’s a way to listen to the stream in my local server through the UDP protocol.
- Working- When in my terminal, if I run
echo 'subscribe' | nc -u 192.168.0.194 9444
, I receive a response for ~15 seconds shown as below which I should be able to convert to an audio that I can play:
?a?????̻?yyzzyyzzzzzzzzz{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}}|||}|}~~~~~~~~~~~}~~~~~~}}~~~}}}}}|||||}|||||||||||}|||||||||||{{{{{{{{{{{{{{zzzzzzzzzzzzzz?a???p?̻?zzzzzzzzzzzzzzyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzywxxxxxwwxxxxxxxxxxxyyyzzyyzyyyyyyyyyzzzyyyyzzzzzzzzz{zz{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{|{|||||||||||||||||||||||||||||?a???P?̻?||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}||||}|}~~~~~~~~~~~}~~~~~~}}}}~~~}}}}|||||}||||||||||||||||||{|||{{{{{{{{{{{{{{{zzzzzzzzzzzzzzzzzzzzzzzzzzzyyyyyyyyyyyyyyyyyyyyyyxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy?a???0?̻?yyyzzzzzzzzzzyzzzyyzzzzzzzzzzzzzzzzzzzzzzxwwwxxxxwwxxxxxxxxxxyyyzyyyyyyyyyyzzzyyyyyyyyzzzzzzzzzzz{zz{z{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}~~~~~~~~~~?a???̻?~~~~}}~~~~~}}}}}}}}}}|||{|}|||||||||}}|||||||{|||{{{{{{{{{{{{{zzzzzzzzzzzzzzzzzzzzzzzzzzzzzyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyxxyyyyyyyyyyyzyyyyzzzzzzzzyyyyyzzzzzzzzzzzzzzzzzzzzxwwwxxxxwwxxxxxxxxxxxyyyyyyyyyyyyzzzyxy?a????̻?yyzzyyzzzzzzzzzzzz{z{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}}||||||}~~~~~~~~~~~~~}}}~~~~~}}~}}}}}}}||{|}|||||||||||||||||{{||{{{{{{{{{{{{{{{zzzzzzzzzzzzzzz?a????̻?zzzzzzzzzzzzzzyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzyyzzzzzzzzzzzzzzzzzzzzzzzzzzzxwwxxxxxwxxxxxxxxxxxyyyzyyzyyyyyyzzzyyyyyyyyzzzzzzzzzzzz{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{|||||||||||||||||||||||||||||?a?İ?̻?||||||||||||||||||||{||{|||||||||||||||||||||||||||||||||||||}}}||||}~~~~~~~~~~~~~~~~~~~~}}}~~~~}}}||||{|}||||||||||||||||||||||{{{{{{{{{{{{{{{zzzzzzzzzzzzzzzzzzzzzzzzzzzyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyxyyyyyyyzy?a?Ɛ?̻?zzzzzzzzzzzzyyzzzzyzzzzzzzzzzzzzzzzzzzzzzxwxxxxwwwxxxxxxxxxxxyyyzyyyyyyyyyzzzyyyyyzyyzzzzzzzzzz{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{|{||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||~~~~~~~~~~?a??p?̻?~~~}}}~~~~~~~~}}}}}}}||{|}||||||||||||}}||{{|||{|{{{{{{{{{{{{{zzzzzzzzzzzzzzzzzzzzzzzzzzzzyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyxyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzxwxxxxwwwxxxxxxxxxxxyyyzyyyyyyzyyyyzzzz?a??P?̻?yyyyyzzzzzzzzzzz{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}}}||||}~~~~~~~~~~~~~~~~~~}}}}}~~}}}}||||{|}|||||||||||||||||{||{|{{{{{{{{{{{{{{zzzzzzzzzzzzzzz?a??0?̻?zzzzzzzzzzzzzyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyxxyyyyyyyyyyyyzyyzzzzzzzzzyyzzzzzzzzzzzzzzzzzzzzzzzywwwxxyyxxwxxxxxxxxxxyyyzyyzyyyyyyzzzyyyyzyyyzzzzzzzzzzz{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{||||||||||||||||||||||||||||||????̻?|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}}}}|}}}~~~~~~~~~~~}~~~~~~}}~~~}}}}}|||||}|||}|||||||||||||||||||{{{{{{{{{{{{{{{{{{zzzzzzzzzzzzzzzzzzzzzzzyyyyyyyyyyyyyyyzzzyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzzzz?a ????̻?zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzywwwxxyyxxxxxxxxxxyyyyyyzyyzyyyyyyzzzzyyyzzzyyzzzzzzzz{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}}}}||}}}~~~~~~~?a...
- Working- I get a similar response when I try to run it in C#:
async Task StartListener(){
UdpClient listener = new UdpClient(9444);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Parse("192.168.0.194"), 9444);
byte[] requestMessage = Encoding.ASCII.GetBytes("subscribe");
await listener.SendAsync(requestMessage, requestMessage.Length, groupEP);
while (true){
await listener.SendAsync(requestMessage, requestMessage.Length, groupEP);
var udpReceiveResult = await listener.ReceiveAsync(); //Waiting for broadcast
byte[] bytes = udpReceiveResult.Buffer;
Console.WriteLine($"Received broadcast from {groupEP} : {Encoding.ASCII.GetString(bytes, 0, bytes.Length)}");
- Not working- In Python, I use the following script but it times out at the receive function, even though Wireshark shows UDP packets (of a similar kind to the Working instances) being initiated and sent from that device, to my laptop correctly. Not sure what’s wrong with my code
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(b"subscribe", ("192.168.0.194", 9444))
sock.connect(("192.168.0.194", 9444))
sock.settimeout(5)
try:
while True:
print("Stream receiving.") # Receive data from UDP
data, addr = sock.recvfrom(1024) # <-GETS STUCK HERE, then times out
print(data) # Doesnt land here, prints nothing
except KeyboardInterrupt:
pass
finally:
sock.close() # Stream stopping
print("Stream closed and socket closed.")
Unhelpful Error message, since without adding the timeout, it just stay stuck at the sock.recvfrom
line and does nothing, even after the device has stopped sending data:
Traceback (most recent call last):
File "/Users/saamer/Documents/GitHub/api/a2.py", line 11, in <module>
data, addr = sock.recvfrom(1024) # Buffer size is ?? bytes
^^^^^^^^^^^^^^^^^^^
TimeoutError: timed out
Eventually I want to be able to do something like this to play the audio