I have a script that has successfully run for a long time. Recently one of my servers was upgraded into Server 2012 and the script is failing to run. It's purpose is to connect to a port and receive some data. The problem here looks like some weird characters that I receive back which I don't know where are they coming from. Any help would much appreciated.
"C:\\Python27\\python.exe" "C:\\gui_update_client.py" hostname/IP address 10000 Filename Server: hostname/IP address, Port: 10000, Master: Filename Connected to nn.nnn.nnn.nn on port 10000 GUI update request sent: Filename Data received: €$Y{gï Data received: Socket error: No data received.
"C:\\Python27\\python.exe" "C:\\gui_update_client.py" hostname/IP address 10000 Filename Server: hostname/IP address, Port: 10000, Master: Filename Connected to hostname/IP address on port 10000 GUI update request sent: Filename Data received: Keep alive
Keep alive received Data received: GUI update completed
Response read: GUI update completed
# Script Arguments
import sys
# Network Client
import socket
# Logging
import logging
# Other
import time
import os
TIMEOUT = 60
DELIM = '\n'
KEEP_ALIVE_MSG = 'Keep alive'
NO_UPDATES_FOUND = 'No GUI updates found'
UPDATE_COMPLETED = 'GUI update completed'
# Check required arguments
try:
server = sys.argv[1]
port = int(sys.argv[2])
master = sys.argv[3]
except:
print 'Usage: {0} server port master'.format(sys.argv[0])
sys.exit(1)
print 'Server: {0}, Port: {1}, Master: {2}'.format(server, port, master)
# Create a TCP/IP socket
sock = socket.create_connection((server, port))
sock.settimeout(TIMEOUT)
print 'Connected to {0} on port {1}'.format(server, str(port))
# Send request and get response
response = ''
try:
# Send GUI update request
sock.sendall(master + DELIM)
print 'GUI update request sent: {0}'.format(master)
# Read the response
data = ''
while response == '':
# Read the response
split = ''
while split != DELIM:
# Buffer the data in small chunks
datum = sock.recv(1024)
print 'Data received: {0}'.format(datum)
if datum == '':
raise socket.error('No data received.')
data += datum
(response, split, remainder) = data.partition(DELIM)
# Check for keep alive response
while response == KEEP_ALIVE_MSG:
print 'Keep alive received'
data = remainder
(response, split, remainder) = data.partition(DELIM)
if split != DELIM:
response = ''
# Response received
print 'Response read: {0}'.format(response)
except socket.timeout as err:
print 'Timeout error: {0}'.format(str(err))
except socket.error as err:
print 'Socket error: {0}'.format(str(err))
finally:
# Clean up the connection
sock.close()
logging.info('Connection to {0} on port {1} closed.'\
.format(server, str(port)))
if response == UPDATE_COMPLETED or response == NO_UPDATES_FOUND:
os.environ['ERRORLEVEL'] = "0"
exit()
else:
os.environ['ERRORLEVEL'] = "1"
exit(1)
Thank you in advance.
Thank you for having a look. I have found what the issue is here. The script is fine. The problem here is that windows listening port is on a different network. When the server was upgraded to 2012 it took as a default a different network card for the service running. That's why the reply comes with weird characters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.