user4719989 user4719989 - 1 year ago 128
Python Question

Send wav files through socket

I am trying to send a wav file through a socket.

I get the error:

TypeError: must be string or buffer, not instance

waveFile =, 'rb')

Answer Source

The wave doesn't give you general file I/O. It is used for getting media properties.

You could use just normal open/close, read/write.

import socket

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); s.connect((HOST,PORT))

with open('input', 'rb') as f:
  for l in f: s.sendall(l)

import socket

(HOST,PORT) = ('localhost',19123)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT)); s.listen(1); conn, addr = s.accept()

with open('output','wb') as f:
  while True:
    l = conn.recv(1024)
    if not l: break
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download