czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

UDP connection issues

Thu Nov 12, 2015 5:39 am

Hi,

I'm trying to set up a basic audio streaming client/server system with two raspberry pi's using python - pyaudio/socket/jack. I know that I have my port and ip correct in both the client and server scripts, but I keep getting the "connection refused" error message. I have set up my server pi for port forwarding. My question is this: does setting up the pi for port forwarding disable other networking connections? When I run netstat on the server pi, I see that the pi is only listening for tcp connection on port 22 (the port forwarding port). This is the only issue that I can imagine at this point... Does anyone know if this is a thing?

Thanks in advance...

czyskows
Posts: 40
Joined: Sun Oct 07, 2012 5:42 am

Re: UDP connection issues

Thu Nov 12, 2015 7:11 am

Here, by the way, is the code I'm using...
Server:

Code: Select all

import pyaudio, sys, socket

port = 5000
chunk = 512
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100

p = pyaudio.PyAudio()
stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, output = True, frames_per_buffer = chunk)

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create the socket
server_socket.bind(('', port)) # listen on port 5000
server_socket.listen(5) # queue max 5 connections
client_socket, address = server_socket.accept()

print "Your IP address is: ", socket.gethostbyname(socket.gethostname())
print "Server Waiting for client on port ", port

while True:

    # test string
    #data = bytearray('DEADBEEF'.decode('hex'))
    #client_socket.sendall(data)
    
   try:
      client_socket.sendall(stream.read(chunk))
   except IOError,e:
      if e[1] == pyaudio.paInputOverflowed: 
         print e 
         x = '\x00'*16*256*2 #value*format*chunk*nb_channels 

stream.stop_stream()
stream.close()
socket.close()
p.terminate()
Client:

Code: Select all

import pyaudio, sys, socket

port = 5000
ip = "change to your ip address"

chunk = 512
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100

p = pyaudio.PyAudio()
stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True,output = True, frames_per_buffer = chunk)

#Create a socket connection for connecting to the server:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((ip, port))

while True:

   #Recieve data from the server:
   data = client_socket.recv(1024)
   stream.write(data,chunk)
   #print data
   
   
socket.close()

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: UDP connection issues

Sun Nov 15, 2015 12:51 pm

What output do you get from your scripts?

What does

Code: Select all

sudo netstat -lntup
say?

I'm not familiar with the libraries you're using, but the question is about UDP and you're opening socket.SOCK_STREAM rather than socket.SOCK_DGRAM. confused...

Return to “Networking and servers”