예제 #1
0
    def handleConnect(self):
        if self.connectionError:
            return
        global hostUserName
        name = self.userName.text()
        self.userName.clear()
        if (name):
            print("UserNameEntered = ", name)
            try:
                funcs.send_message(clientSock, 0, hostMacAdress + ',' + name)
                uno, fno, size = funcs.recieve_header(clientSock)
                reply = funcs.recieve_message(clientSock, size)
                self.serverStatus.setText(reply)
                print(reply)
                if reply[0] == 'C':
                    uno, fno, size = funcs.recieve_header(clientSock)
                    hostUserName = name
                    hostUserNo = uno
                    QtCore.QTimer.singleShot(200, self.close)

            except (ConnectionError):
                self.appName.setText("Cannot Connect, press Exit to Exit")
                self.connectionError = True
        else:
            self.serverStatus.setText("Enter a valid name")
예제 #2
0
 def handleClose(self):
     message = self.room + self.hostUserName + " left the room."
     try:
         with sockLock:
             funcs.send_message(self.clientSock, self.hostUserNo, message)
         self.close()
     except ConnectionError:
         self.chat.append("Server seems offline")
예제 #3
0
def send_transaction(sock, User):
    while True:
        print("waiting for transaction to be sent")
        payload = json.loads(
            redis_connection.blpop(SEND_TRANSACTIONS_QUEUE_KEY)[1].decode(
                'utf-8'))
        transaction = Transaction.from_redis(redis_connection, payload)
        print("try to send the received transaction")
        serial = pickle.dumps(transaction)
        funcs.send_message(sock, "Transaction")
        funcs.send_bytes(sock, serial)
예제 #4
0
 def handleSend(self):
     message = self.userChat.toPlainText()
     if not message:
         return
     self.userChat.clear()
     self.updateChat(self.hostUserName + " : " + message)
     message = self.room + self.hostUserName + " : " + message
     try:
         #print(message)
         with sockLock:
             print("Sending ", message)
             funcs.send_message(self.clientSock, self.hostUserNo, message)
     except ConnectionError:
         self.chat.append("Server seems offline")
예제 #5
0
 def __init__(self, sock, uno, fno, rno, uname, fname, parent=None):
     super(readingThread, self).__init__(parent)
     self.parent = parent
     self.clientSock = sock
     self.roomNo = rno
     self.fileName = fname
     self.hostUserNo = uno
     self.fileNo = fno
     self.hostUserName = uname
     self.f = open(self.fileName, 'rb')
     with sockLock:
         print("Sending - " + self.roomNo + self.fileName + " " +
               self.hostUserName)
         funcs.send_message(self.clientSock, self.hostUserNo, self.roomNo +
                            self.fileName + " " + self.hostUserName,
                            self.fileNo)  # sent first signal
예제 #6
0
def index():
    if request.method == 'POST':
        response = request.get_json()
        try:
            chat_id = response['message']['chat']['id']
            message = response['message']['text']
        except KeyError:
            chat_id = response['edited_message']['chat']['id']
            message = response['edited_message']['text']
        finally:
            currency = f.parse_text(message)
            f.send_message(
                chat_id, f.get_price(currency)
            ) if currency else f.send_message(chat_id)
            return jsonify(response)
    else:
        return '<h1>Hello, world!</h1>'
예제 #7
0
 def handleFileSend(self):
     fileName = self.userChat.toPlainText()
     if not fileName:
         return
     print("Sending Filename = " + fileName)
     self.updateChat("Sending Filename " + fileName)
     msg = self.room + self.hostUserName + " is sending file " + fileName
     try:
         with sockLock:
             funcs.send_message(self.clientSock, self.hostUserNo, msg)
         th = readingThread(self.clientSock, self.hostUserNo, self.fileNo,
                            self.room, self.hostUserName, fileName, self)
         th.sendingCompleteSignal.connect(self.sendingComplete)
         self.fileNo += 1
         th.start()
     except ConnectionError:
         self.chat.append("Server seems offline")
예제 #8
0
def miner_thread(sock, User):
    miner = Miner(redis_connection, User)

    while True:
        print("trying to mine")
        block = miner.mine()
        if block == None:
            redis_connection.set("StopMining", "No")
            print("Puzzle solved by other node")
            continue

        print("have a block, broadcasting")
        #funcs.send_message(sock, block.to_redis())
        #funcs.send_object(block)
        serial = pickle.dumps(block)
        print("Serialized block = ")
        print(serial)
        print(json.dumps(block.to_json(), indent=4))
        #print(json.dumps(bl.to_json(),indent = 4))
        funcs.send_message(sock, "Block")
        funcs.send_bytes(sock, serial)
예제 #9
0
def handle_file_send(sock, file_num, uno, file_name, user_name, room):
    if len(room) < 3:
        room = '0' * (3 - len(room)) + room
    print("handling file {} num {} room {}".format(file_name, file_num, room))
    f = open(file_name, 'rb')
    with socket_lock:
        funcs.send_message(sock, uno, room + file_name + ',' + user_name,
                           file_num)
    room = room.encode('utf-8')
    data = f.read(funcs.CHUNK_SIZE)
    while data != b'':
        data = room + data
        data = funcs.create_packet(uno, file_num, data)
        with socket_lock:
            funcs.send_data(sock, data)
        data = f.read(funcs.CHUNK_SIZE)
    #Sending closing information
    data = room + data
    data = funcs.create_packet(uno, file_num, data)
    with socket_lock:
        funcs.send_data(sock, data)

    print('File {} transfered'.format(file_name))
    f.close()
예제 #10
0
def RegisterClient(sock,client_user_no,q):
	client_key = None
	try:
		retry = True
		while retry:
			uno, fno, size = funcs.recieve_header(sock)
			if fno == 999:
				mac_client, client_name = funcs.recieve_message(sock, size).split(',')
				with connected_lock:
					if connected.get(client_name, None):
						print('Client {} already present'.format(client_name))
					else:
						print('Client {}@{} registered'.format(mac_client, client_name))
						retry = False
				if retry:
					funcs.send_message(sock, 0, 'Server: Client named {} already present'.format(client_name))
				else:
					funcs.send_message(sock, 0, 'Connected to ' + appname + ' ' + version)
			else:
				print('Client name not recieved')
		print('Client {} : {} user_number = {}'.format(client_name, mac_client, client_user_no))
		client_key = mac_client + '@' + str(client_user_no)
		with send_queues_lock:
			send_queues[client_key] = q
		with address_to_name_lock:
			address_to_name[client_key] = client_name
		with connected_lock:
			connected[client_name] = client_key
		# sending user number
		funcs.send_message(sock, client_user_no, '')

		sending_thread = threading.Thread(target=handle_client_send, args=[sock, client_key, q], daemon=True)
		sending_thread.start()
		return client_name,mac_client,client_key

	except (EOFError, ConnectionError):
		handle_disconnect(sock, client_key)
		return None,None,None
예제 #11
0
 elif 'connect' == inp[0]:
     inp = inp[1]
     funcs.send_connect(sock, host_user_no, inp)
 elif 'roomchat' == inp[0]:
     inp = inp[1].split(' ', 1)
     room = inp[0]
     with room_lock:
         if not room in room_list:
             print("Invalid room")
             continue
     message = name + ": " + inp[1]
     if len(room) < 3:
         room = '0' * (3 - len(room)) + room
     message = room + message
     with socket_lock:
         funcs.send_message(sock, host_user_no, message)
 elif 'roomsend' == inp[0]:
     signal = inp[1].split(' ', 1)
     room = signal[0]
     with room_lock:
         if not room in room_list:
             print("Invalid room")
             continue
     files = signal[1].split(',')
     for f in files:
         print('file {}'.format(f))
         file_no += 1
         send_thread = threading.Thread(
             target=handle_file_send,
             args=[sock, file_no, host_user_no, f, name, room],
             daemon=True)
예제 #12
0
 def sendRefresh(self):
     with sockLock:
         funcs.send_message(self.clientSock, self.hostUserNo, '', 997)