I am beginner in programming I have a program to sending .wav files via TCP sockets in python from web. Program works fine but i have question. When transfer is complete between server and client, program on server side is still running. Is there a way how "kill him"? I mean after transfer is complete, program will end by itself. Sorry for bad English. Here is code:
import socket # Import socket module
import os
port = 60001 # Reserve a port for your service.
s = socket.socket() # Create a socket object
host = socket.gethostname()
# Get local machine name
s.bind((host, port))
f = open('fare.wav', 'wb')
# Bind to the port
s.listen(1) # Now wait for client connection.
print 'Server listening....'
while True:
conn, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
print "Recieving..."
l = conn.recv(4096)
while (l):
print "Recieving..."
f.write(l)
l = conn.recv(4096)
f.close()
print('Done receiving')
conn.send('Thank you for connecting')
conn.close()
Client:
import os
import socket
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 60001 # Reserve a port for your service.
s.connect((host, port))
f = open('fanfare2.wav','rb')
print("Sending...")
l = f.read(4096)
while (l):
print("Sending...")
s.send(l)
l = f.read(4096)
f.close()
print("Done Sending")
s.shutdown(socket.SHUT_WR)
print s.recv(1024)
s.close()