server.py
import socket
import time
HOST = '192.168.1.85'
PORT = 9191 # Arbitrary port (not recommended)
LOG_FILE = 'c:/temp/sockserver.log'
mySock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySock.bind((HOST, PORT))
logfile = open(LOG_FILE, 'w')
try:
print >> logfile, '*** Server started : %s' % time.strftime('%Y-%m-%d %H:%M:%S')
while 1:
data, addr = mySock.recvfrom(1024)
print >> logfile, '%s (%s): %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), addr, data)
if data == 'STOPSERVER':
print >> logfile, '*** Server shutdown at %s by %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), addr)
break
finally:
logfile.close()
client.py
import socket
import sys
PORT = 9191 # Same port as the server
HOST = '127.0.0.1'
mySock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySock.sendto('Hello World !', (HOST, PORT))
mySock.sendto('Do U hear me?', (HOST, PORT))
mySock.sendto('STOPSERVER', (HOST, PORT))
import sys
PORT = 9191 # Same port as the server
HOST = '127.0.0.1'
mySock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySock.sendto('Hello World !', (HOST, PORT))
mySock.sendto('Do U hear me?', (HOST, PORT))
mySock.sendto('STOPSERVER', (HOST, PORT))
이 로직을 사용하여 ODI 실행도중 예기치 못한 상황이 발생하였을 때 소켓통신을 통해서 Server의 관리자에게 메세지 보내는 방도로도 사용이 가능할 것으로 보인다.