Commit fa26ffa6 authored by Pedro Oliveira's avatar Pedro Oliveira

fix pip install failure && client.py and server.py dont throw exception after Ctrl^C

parent a11b869c
...@@ -7,4 +7,4 @@ ip route add 0.0.0.0/0 via 10.1.0.2 ...@@ -7,4 +7,4 @@ ip route add 0.0.0.0/0 via 10.1.0.2
# install python # install python
apt-get update && apt-get --assume-yes install python3 python3-pip apt-get update && apt-get --assume-yes install python3 python3-pip
pip-3.2 install netifaces pip-3.2 install --index-url=https://pypi.python.org/simple/ netifaces
...@@ -2,7 +2,16 @@ import socket ...@@ -2,7 +2,16 @@ import socket
import struct import struct
import sys import sys
import netifaces import netifaces
import signal
import sys
is_running = True
sock = None
def exit(signal, frame):
is_running = False
sock.close()
sys.exit(0)
def chooseInterface(): def chooseInterface():
interfaces = netifaces.interfaces() interfaces = netifaces.interfaces()
...@@ -25,6 +34,10 @@ def chooseInterface(): ...@@ -25,6 +34,10 @@ def chooseInterface():
if not hasattr(socket, 'SO_BINDTODEVICE'): if not hasattr(socket, 'SO_BINDTODEVICE'):
socket.SO_BINDTODEVICE = 25 socket.SO_BINDTODEVICE = 25
signal.signal(signal.SIGINT, exit)
signal.signal(signal.SIGTERM, exit)
multicast_group = '224.12.12.12' multicast_group = '224.12.12.12'
server_address = ('', 10000) server_address = ('', 10000)
...@@ -50,7 +63,7 @@ sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, ...@@ -50,7 +63,7 @@ sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP,
# Receive/respond loop # Receive/respond loop
while True: while is_running:
#print >>sys.stderr, '\nwaiting to receive message' #print >>sys.stderr, '\nwaiting to receive message'
data, address = sock.recvfrom(10240) data, address = sock.recvfrom(10240)
print(data.decode("utf-8")) print(data.decode("utf-8"))
......
...@@ -3,6 +3,16 @@ import struct ...@@ -3,6 +3,16 @@ import struct
import sys import sys
import netifaces import netifaces
import traceback import traceback
import signal
is_running = True
sock = None
def exit(signal, frame):
is_running = False
sock.close()
sys.exit(0)
def chooseInterface(): def chooseInterface():
interfaces = netifaces.interfaces() interfaces = netifaces.interfaces()
...@@ -23,8 +33,9 @@ def chooseInterface(): ...@@ -23,8 +33,9 @@ def chooseInterface():
return inputValue return inputValue
signal.signal(signal.SIGINT, exit)
signal.signal(signal.SIGTERM, exit)
#message = 'very important data'
multicast_group = ('224.12.12.12', 10000) multicast_group = ('224.12.12.12', 10000)
# Create the datagram socket # Create the datagram socket
...@@ -42,11 +53,10 @@ ip_interface = netifaces.ifaddresses(interface_name)[netifaces.AF_INET][0]['addr ...@@ -42,11 +53,10 @@ ip_interface = netifaces.ifaddresses(interface_name)[netifaces.AF_INET][0]['addr
sock.bind((ip_interface, 10000)) sock.bind((ip_interface, 10000))
try: try:
# Look for responses from all recipients # Look for responses from all recipients
while True: while is_running:
input_msg = input('msg --> ') input_msg = input('msg --> ')
try: try:
sock.sendto(input_msg.encode("utf-8"), multicast_group) sock.sendto(input_msg.encode("utf-8"), multicast_group)
except: except:
traceback.print_exc() traceback.print_exc()
continue continue
......
...@@ -7,4 +7,4 @@ ip route add 0.0.0.0/0 via 10.0.2.3 ...@@ -7,4 +7,4 @@ ip route add 0.0.0.0/0 via 10.0.2.3
# install python # install python
apt-get update && apt-get --assume-yes install python3 python3-pip apt-get update && apt-get --assume-yes install python3 python3-pip
pip-3.2 install netifaces pip-3.2 install --index-url=https://pypi.python.org/simple/ netifaces
...@@ -2,7 +2,16 @@ import socket ...@@ -2,7 +2,16 @@ import socket
import struct import struct
import sys import sys
import netifaces import netifaces
import signal
import sys
is_running = True
sock = None
def exit(signal, frame):
is_running = False
sock.close()
sys.exit(0)
def chooseInterface(): def chooseInterface():
interfaces = netifaces.interfaces() interfaces = netifaces.interfaces()
...@@ -25,6 +34,10 @@ def chooseInterface(): ...@@ -25,6 +34,10 @@ def chooseInterface():
if not hasattr(socket, 'SO_BINDTODEVICE'): if not hasattr(socket, 'SO_BINDTODEVICE'):
socket.SO_BINDTODEVICE = 25 socket.SO_BINDTODEVICE = 25
signal.signal(signal.SIGINT, exit)
signal.signal(signal.SIGTERM, exit)
multicast_group = '224.12.12.12' multicast_group = '224.12.12.12'
server_address = ('', 10000) server_address = ('', 10000)
...@@ -50,7 +63,7 @@ sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, ...@@ -50,7 +63,7 @@ sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP,
# Receive/respond loop # Receive/respond loop
while True: while is_running:
#print >>sys.stderr, '\nwaiting to receive message' #print >>sys.stderr, '\nwaiting to receive message'
data, address = sock.recvfrom(10240) data, address = sock.recvfrom(10240)
print(data.decode("utf-8")) print(data.decode("utf-8"))
......
...@@ -3,6 +3,16 @@ import struct ...@@ -3,6 +3,16 @@ import struct
import sys import sys
import netifaces import netifaces
import traceback import traceback
import signal
is_running = True
sock = None
def exit(signal, frame):
is_running = False
sock.close()
sys.exit(0)
def chooseInterface(): def chooseInterface():
interfaces = netifaces.interfaces() interfaces = netifaces.interfaces()
...@@ -23,8 +33,9 @@ def chooseInterface(): ...@@ -23,8 +33,9 @@ def chooseInterface():
return inputValue return inputValue
signal.signal(signal.SIGINT, exit)
signal.signal(signal.SIGTERM, exit)
#message = 'very important data'
multicast_group = ('224.12.12.12', 10000) multicast_group = ('224.12.12.12', 10000)
# Create the datagram socket # Create the datagram socket
...@@ -42,11 +53,10 @@ ip_interface = netifaces.ifaddresses(interface_name)[netifaces.AF_INET][0]['addr ...@@ -42,11 +53,10 @@ ip_interface = netifaces.ifaddresses(interface_name)[netifaces.AF_INET][0]['addr
sock.bind((ip_interface, 10000)) sock.bind((ip_interface, 10000))
try: try:
# Look for responses from all recipients # Look for responses from all recipients
while True: while is_running:
input_msg = input('msg --> ') input_msg = input('msg --> ')
try: try:
sock.sendto(input_msg.encode("utf-8"), multicast_group) sock.sendto(input_msg.encode("utf-8"), multicast_group)
except: except:
traceback.print_exc() traceback.print_exc()
continue continue
......
...@@ -7,4 +7,4 @@ ip route add 0.0.0.0/0 via 10.0.3.4 ...@@ -7,4 +7,4 @@ ip route add 0.0.0.0/0 via 10.0.3.4
# install python # install python
apt-get update && apt-get --assume-yes install python3 python3-pip apt-get update && apt-get --assume-yes install python3 python3-pip
pip-3.2 install netifaces pip-3.2 install --index-url=https://pypi.python.org/simple/ netifaces
...@@ -2,7 +2,16 @@ import socket ...@@ -2,7 +2,16 @@ import socket
import struct import struct
import sys import sys
import netifaces import netifaces
import signal
import sys
is_running = True
sock = None
def exit(signal, frame):
is_running = False
sock.close()
sys.exit(0)
def chooseInterface(): def chooseInterface():
interfaces = netifaces.interfaces() interfaces = netifaces.interfaces()
...@@ -25,6 +34,10 @@ def chooseInterface(): ...@@ -25,6 +34,10 @@ def chooseInterface():
if not hasattr(socket, 'SO_BINDTODEVICE'): if not hasattr(socket, 'SO_BINDTODEVICE'):
socket.SO_BINDTODEVICE = 25 socket.SO_BINDTODEVICE = 25
signal.signal(signal.SIGINT, exit)
signal.signal(signal.SIGTERM, exit)
multicast_group = '224.12.12.12' multicast_group = '224.12.12.12'
server_address = ('', 10000) server_address = ('', 10000)
...@@ -50,7 +63,7 @@ sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, ...@@ -50,7 +63,7 @@ sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP,
# Receive/respond loop # Receive/respond loop
while True: while is_running:
#print >>sys.stderr, '\nwaiting to receive message' #print >>sys.stderr, '\nwaiting to receive message'
data, address = sock.recvfrom(10240) data, address = sock.recvfrom(10240)
print(data.decode("utf-8")) print(data.decode("utf-8"))
......
...@@ -3,6 +3,16 @@ import struct ...@@ -3,6 +3,16 @@ import struct
import sys import sys
import netifaces import netifaces
import traceback import traceback
import signal
is_running = True
sock = None
def exit(signal, frame):
is_running = False
sock.close()
sys.exit(0)
def chooseInterface(): def chooseInterface():
interfaces = netifaces.interfaces() interfaces = netifaces.interfaces()
...@@ -23,8 +33,9 @@ def chooseInterface(): ...@@ -23,8 +33,9 @@ def chooseInterface():
return inputValue return inputValue
signal.signal(signal.SIGINT, exit)
signal.signal(signal.SIGTERM, exit)
#message = 'very important data'
multicast_group = ('224.12.12.12', 10000) multicast_group = ('224.12.12.12', 10000)
# Create the datagram socket # Create the datagram socket
...@@ -42,11 +53,10 @@ ip_interface = netifaces.ifaddresses(interface_name)[netifaces.AF_INET][0]['addr ...@@ -42,11 +53,10 @@ ip_interface = netifaces.ifaddresses(interface_name)[netifaces.AF_INET][0]['addr
sock.bind((ip_interface, 10000)) sock.bind((ip_interface, 10000))
try: try:
# Look for responses from all recipients # Look for responses from all recipients
while True: while is_running:
input_msg = input('msg --> ') input_msg = input('msg --> ')
try: try:
sock.sendto(input_msg.encode("utf-8"), multicast_group) sock.sendto(input_msg.encode("utf-8"), multicast_group)
except: except:
traceback.print_exc() traceback.print_exc()
continue continue
......
rm -rf MulticastRouting/ rm -rf MulticastRouting/
cp -rf /hosthome/Desktop/pim/ MulticastRouting/ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd MulticastRouting cd MulticastRouting
pip-3.2 install -r requirements.txt pip-3.2 install --index-url=https://pypi.python.org/simple/ -r requirements.txt
python3 Run.py -stop python3 Run.py -stop
python3 Run.py -start python3 Run.py -start
......
rm -rf MulticastRouting/ rm -rf MulticastRouting/
cp -rf /hosthome/Desktop/pim/ MulticastRouting/ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd MulticastRouting cd MulticastRouting
pip-3.2 install -r requirements.txt pip-3.2 install --index-url=https://pypi.python.org/simple/ -r requirements.txt
python3 Run.py -stop python3 Run.py -stop
python3 Run.py -start python3 Run.py -start
......
rm -rf MulticastRouting/ rm -rf MulticastRouting/
cp -rf /hosthome/Desktop/pim/ MulticastRouting/ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd MulticastRouting cd MulticastRouting
pip-3.2 install -r requirements.txt pip-3.2 install --index-url=https://pypi.python.org/simple/ -r requirements.txt
python3 Run.py -stop python3 Run.py -stop
python3 Run.py -start python3 Run.py -start
......
rm -rf MulticastRouting/ rm -rf MulticastRouting/
cp -rf /hosthome/Desktop/pim/ MulticastRouting/ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd MulticastRouting cd MulticastRouting
pip-3.2 install -r requirements.txt pip-3.2 install --index-url=https://pypi.python.org/simple/ -r requirements.txt
python3 Run.py -stop python3 Run.py -stop
python3 Run.py -start python3 Run.py -start
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment