The following script receiving data from a socket connection does not react to the CTRL+C signal sent in order to exit:
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
"""
import socket
HOST = '192.168.178.1'
PORT = 1012
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while 1:
data = s.recv(1024)
print 'Received', repr(data)
s.close()
How can the program be modified so that program input or the default signal causes the infinite loop to be broken in order to end the program gracefully?