コード例 #1
0
ファイル: Logger.py プロジェクト: Dur/Inzynierka
	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
コード例 #2
0
ファイル: Connection.py プロジェクト: Dur/Inzynierka
	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
コード例 #3
0
ファイル: PingConnection.py プロジェクト: Dur/Inzynierka
	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