from __future__ import print_function
from decimal import *
import socket as sckt

class Communicate():

	def __init__(self):

		self.clntSckt = sckt.socket(sckt.AF_INET, sckt.SOCK_STREAM)
		self.stus = False
		self.host = 'rPi3'
		self.port = 60606
		self.resp = ''

	def estConn(self):

		try:
			self.clntSckt.connect((self.host, self.port))
		except OSError:
			self.clntSckt = sckt.socket(sckt.AF_INET, sckt.SOCK_STREAM)
			self.clntSckt.connect((self.host, self.port))

	def dropConn(self):

		self.clntSckt.shutdown(sckt.SHUT_RDWR)
		self.clntSckt.close()

	def sendCmnd(self, cmnd):

		self.clntSckt.send(cmnd.encode())

	def recvResp(self, size):

		resp = self.clntSckt.recv(size)
		return resp
