Skip to content
Permalink
a926525190
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
32 lines (27 sloc) 855 Bytes
import socket
#### Connection to Server
host = '127.0.0.1'
port = 5001
# Create Socket and connect to server
thisSocket = socket.socket()
thisSocket.connect((host,port))
def receiveMessage():
''' Receives multiple messages from server if needed, until server
sends EndOfMessage '''
message = thisSocket.recv(1024).decode()
while (message != "EndOfMessage"):
print("Server: {}".format(message))
thisSocket.send("Received".encode())
message = thisSocket.recv(1024).decode()
receiveMessage()
while True:
sendMessage = input("Send: ")
if (sendMessage is None or sendMessage == ""):
continue
if (sendMessage == "end"):
break
thisSocket.send(sendMessage.encode())
receiveMessage()
#Close Socket
thisSocket.close()
print("Conversation between user and ChatBot Ended")