From a1360e292dd30d2933d2f5706702491b7ee5d918 Mon Sep 17 00:00:00 2001 From: Andre Mateus Silva Date: Wed, 1 Nov 2017 12:53:33 +0000 Subject: [PATCH] Not working, still trying to work with determineUserInput function --- Client.py | 1 + Server.py | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Client.py b/Client.py index ced2f79..6faf945 100644 --- a/Client.py +++ b/Client.py @@ -12,6 +12,7 @@ def receiveMessage(): print("Jeff: {}".format(message)) thisSocket.send("Received".encode()) message = thisSocket.recv(1024).decode() + print ("Connected to Jeff") while True: diff --git a/Server.py b/Server.py index ae9920c..4fae49d 100644 --- a/Server.py +++ b/Server.py @@ -2,7 +2,7 @@ import socket import time import random from DataAPI import getQuestion, getCategories -from Get_Functions import getName +from what_Recog import determineUserInput # Create Socket and bind server to socket thisSocket = socket.socket() @@ -29,28 +29,41 @@ def sendMessage(message, EOM = True): print("SERVER: {}".format(message)) resp = conn.recv(1024).decode() # Waits for client feedback -def receiveMessage(): +def receiveMessage(expectedType = "Igone"): ''' Receive a message from the client and check if received correctly, returns the message ''' - message = conn.recv(1024).decode() - if not message: # If message is None, try to receive again - sendMessage("Sorry, I couldn't get that, can you repeat?") + if (expectedType != "Ignore"): message = conn.recv(1024).decode() - if not message: # Couldn't receive message, exit - sendMessage("Sorry, I not able to receive that, plese try again another day.") - exit() - print ("CLIENT: {}".format(message)) - return(message) + if not message: # If message is None, try to receive again + sendMessage("Sorry, I couldn't get that, can you repeat?") + message = conn.recv(1024).decode() + if not message: # Couldn't receive message, exit + sendMessage("Sorry, I not able to receive that, plese try again another day.") + exit() + + print ("CLIENT: {}".format(message)) + + answerUserInput = determineUserInput(message) + + return(message) + else: + return (None) receiveMessage() # Say hi to client and get name sendMessage("Hi! What's your name?") -clientName = getName(receiveMessage()) +clientName = receiveMessage() + + +while userInput[1] != expectedType: + sendMessage("The answer to your question is {}".format(userInput[0])) + sendMessage("So, {}, I will teach you something today!" .format(clientName.title()), False) +print() sendMessage("Pick a subject.", False) cat = getCategories(True, 3) sendMessage(cat[0], False)