13 from GlobalDicts
import HOST,PORT_GUI
22 self.
logger = logging.getLogger(
"SP.TCPClient")
23 self.logger.debug(
"Constructor TCPClient PORT to send %d" % PORT_GUI)
47 self.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
49 except socket.error, msg:
51 self.logger.info(
'Failed to create socket. Error code: %d Error message : %d ' % (msg[0], msg[1]))
55 self.sock.connect((HOST, PORT_GUI))
56 self.logger.debug(
"OK for connection to %d" % PORT_GUI)
59 self.logger.debug(
"ONLY_CHECK, close the socket")
65 except socket.error, ex:
68 self.logger.info(
'Failed in socket.connect. Error code: %d, Error message : %s' % (ex[0], ex[1]) )
75 self.logger.error(
"Get a base exception in connect(), SHOULD NOT HAPPEN. no connection possible")
83 self.logger.debug(
"Entry SendData")
84 self.logger.debug(
"Data to send %s" % data)
87 self.logger.debug(
"status %d" % status)
89 self.logger.info(
"GUI Server NOT RUNNING")
95 nb_bytes_send = self.sock.send(data +
" END")
96 self.logger.debug(
"nb_bytes_send %d" % nb_bytes_send)
97 except socket.error, ex:
98 self.logger.error(
"Get exception socket.error in connect(), no connection possible")
99 self.logger.error(
'Failed in socket.coonect. Error code: ' + str(ex[0]) +
' , Error message : ' + ex[1])
111 if __name__ ==
"__main__":
117 data=
"DJ,2014-09-22 22:08:09,17172.680000,74298798.000000"
128 print "GetActivity ", tcp.GetActivity()
136 received = tcp.SendData( data )
138 print "Sent: %s" % data
139 print "Received: %s" % received
Make a connection to the root application server to send directly new data.
active
default true at creation, SendData will send back false if the connection is impossible.
def SendData
Connect to the server send the data no answer at this point Close the socket.
def Connect
Try to connect to the server.