Esempio n. 1
0
class PingConnection(object):

	_stream = None

	def __init__(self, configFile):
		self.configFile = configFile
		self.dictionary=dict()
		with open(self.configFile, 'r') as f:
			for singleLine in f:
				singleLine = singleLine.replace('\n','')
				splitedLine = singleLine.split('=')
				self.dictionary[splitedLine[0]] = splitedLine[1]
		self._socket = None

	def connect(self, host, port, resource):
		self.dictionary['server_port'] = port
		self.dictionary['server_host'] = host
		self.dictionary['resource'] = resource
		self._socket = socket.socket()
		self._socket.settimeout(int(self.dictionary.get('socket_timeout')))
		try:
			logging.info(NAME + "connecting to " + host + ":" + str(port) + resource )
			self._socket.connect((host,int(port)))
			if self.dictionary.get('use_tls') == 'True':
				self._socket = _TLSSocket(self._socket)

			version = self.dictionary.get('protocol_version')

			self._handshake = ClientHandshakeProcessor(
				self._socket, self.dictionary)

			self._handshake.handshake()

			request = ClientRequest(self._socket)

			version_map = {
			_PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13}
			request.ws_version = version_map[version]

			stream_option = StreamOptions()
			stream_option.mask_send = True
			stream_option.unmask_receive = False

			self._stream = Stream(request, stream_option)
			logging.info(NAME+ "Polaczenie nawiazane")
			return CONNECTION_OK_FLAG
		except Exception, e:
			self._socket.close()
			logging.error(NAME+ "Nie mozna nawiazac polaczenia")
			logging.error(NAME + e.message)
			return CONNECTION_PROBLEM_FLAG
Esempio n. 2
0
	def connect(self, host, port, resource):
		self._socket = socket.socket()
		self.dictionary['server_port'] = port
		self.dictionary['server_host'] = host
		self.dictionary['resource'] = resource
		self._socket.settimeout(int(self.dictionary.get('socket_timeout')))
		try:
			self._socket.connect((host, int(port)))
			self.isConnected = True
			if self.dictionary.get('use_tls') == 'True':
				self._socket = _TLSSocket(self._socket)

			version = self.dictionary.get('protocol_version')

			self._handshake = ClientHandshakeProcessor(
				self._socket, self.dictionary)

			self._handshake.handshake()

			request = ClientRequest(self._socket)

			version_map = {
			_PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13}
			request.ws_version = version_map[version]

			stream_option = StreamOptions()
			stream_option.mask_send = True
			stream_option.unmask_receive = False

			self._stream = Stream(request, stream_option)
			return OK_FLAG
		except Exception, e:
			self.isConnected = False
			print(e.message)
			return ERROR_FLAG
Esempio n. 3
0
class Connection(object):

	def __init__(self, configFile):
		self.configFile = configFile
		configReader = ConfigurationReader(self.configFile)
		self.dictionary=configReader.readConfigFile()
		self._socket = None
		self.list=[]

	def connect(self, host, port, resource):
		self._socket = socket.socket()
		self.dictionary['server_port'] = port
		self.dictionary['server_host'] = host
		self.dictionary['resource'] = resource
		self._socket.settimeout(int(self.dictionary.get('socket_timeout')))
		try:
			logger.logInfo(NAME + "connecting to " + host + ":" + str(port) + resource )
			self._socket.connect((host, int(port)))
			if self.dictionary.get('use_tls') == 'True':
				self._socket = _TLSSocket(self._socket)

			version = self.dictionary.get('protocol_version')

			self._handshake = ClientHandshakeProcessor(
				self._socket, self.dictionary)

			self._handshake.handshake()

			logger.logInfo(NAME + 'Nawiazano polaczenie z ' + host+":"+str(port))

			request = ClientRequest(self._socket)

			version_map = {
				_PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13}
			request.ws_version = version_map[version]

			stream_option = StreamOptions()
			stream_option.mask_send = True
			stream_option.unmask_receive = False

			self._stream = Stream(request, stream_option)
			return OK_FLAG
		except Exception, e:
			logger.logError(NAME+"Wystapil problem")
			logger.logError(NAME + e.message)
			print(e.message)
			return ERROR_FLAG
Esempio n. 4
0
	def connect(self, host, port, resource):
		self.dictionary['server_port'] = port
		self.dictionary['server_host'] = host
		self.dictionary['resource'] = resource
		self._socket = socket.socket()
		self._socket.settimeout(int(self.dictionary.get('socket_timeout')))
		try:
			logging.info(NAME + "connecting to " + host + ":" + str(port) + resource )
			self._socket.connect((host,int(port)))
			if self.dictionary.get('use_tls') == 'True':
				self._socket = _TLSSocket(self._socket)

			version = self.dictionary.get('protocol_version')

			self._handshake = ClientHandshakeProcessor(
				self._socket, self.dictionary)

			self._handshake.handshake()

			request = ClientRequest(self._socket)

			version_map = {
			_PROTOCOL_VERSION_HYBI13: common.VERSION_HYBI13}
			request.ws_version = version_map[version]

			stream_option = StreamOptions()
			stream_option.mask_send = True
			stream_option.unmask_receive = False

			self._stream = Stream(request, stream_option)
			logging.info(NAME+ "Polaczenie nawiazane")
			return CONNECTION_OK_FLAG
		except Exception, e:
			self._socket.close()
			logging.error(NAME+ "Nie mozna nawiazac polaczenia")
			logging.error(NAME + e.message)
			return CONNECTION_PROBLEM_FLAG