Added logger and wrapped while loop in a try/except and log any errors.

This commit is contained in:
2018-03-20 13:54:11 +01:00
parent 0f3201f1bf
commit 4ebd11ea40

View File

@@ -2,18 +2,24 @@
from socket import *
from macLookup import getTimes
import json
import logging
log = logging.getLogger(__name__)
# Define the socket communicating will transfered
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', 12001))
while True:
# Save the message and return address to variables.
message, address = serverSocket.recvfrom(1024)
try:
# Save the message and return address to variables.
message, address = serverSocket.recvfrom(1024)
print(message, address) # Debug print
print(message, address) # Debug print
times = json.dumps(getTimes())
# This should prob be cases and not if's, but works to get the right info user requests.
serverSocket.sendto(bytes(times, 'utf-8'), address)
times = json.dumps(getTimes())
# This should prob be cases and not if's, but works to get the right info user requests.
serverSocket.sendto(bytes(times, 'utf-8'), address)
# serverSocket.close()
except Exception as e:
log.info(e.message, e.args)