Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
chatBot/server_code.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
45 lines (40 sloc)
1.64 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
def Main(): | |
#Give ChatBot server an IP address and port | |
host = "127.0.0.1" | |
port = 50036 | |
#Create Socket and bind server to socket | |
thisSocket = socket.socket() | |
thisSocket.bind((host,port)) | |
#Listen for clients | |
thisSocket.listen(1) | |
#Connect to client | |
conn, addr = thisSocket.accept() | |
#print Connect ip address | |
print ("The Connection ip is : " + str(addr)) | |
#Repear forever | |
saudations = "Hi user, i am Foodie and am here to help you to decide what will be your meal" | |
conn.send(saudations.encode()) | |
while True: | |
#Receive info from client | |
receiveMess = conn.recv(1024).decode() | |
#if no info from client end loop | |
if not receiveMess: | |
break | |
#Print info from client | |
print ("Message from User to Chatbot : " + str(receiveMess)) | |
#set return message | |
checkUser = "Hi user, are you already registered ?" | |
conn.send(checkUser.encode()) | |
receiveCheckUser = conn.recv(1024).decode() | |
if receiveCheckUser == "y" or receiveCheckUser == "Y": | |
#implement login form | |
username = "hi carlos" | |
conn.send(checkUser.encode()) | |
else: | |
createAcc = "do you want to create an account ?" | |
conn.send(createAcc.encode()) | |
conn.close() | |
if __name__ == '__main__': | |
Main() |