2023-11-06 20:38:25 +01:00
|
|
|
# BASIC CLIENT FOR INTERACTING WITH THE SERVER
|
|
|
|
# This client is used to test the server and to interact with it
|
|
|
|
import json
|
|
|
|
|
|
|
|
import socketio
|
|
|
|
|
|
|
|
HOST = "localhost"
|
|
|
|
PORT = 6000
|
|
|
|
waiting = False
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
# Create a TCP/IP socket
|
|
|
|
sock = socketio.Client()
|
|
|
|
sock.connect(f"http://{HOST}:{PORT}")
|
|
|
|
|
|
|
|
# Join the room
|
|
|
|
sock.emit('join', json.dumps({'uuid': 'clientpc'}))
|
|
|
|
|
2023-11-06 21:38:38 +01:00
|
|
|
|
2023-11-06 20:38:25 +01:00
|
|
|
# Listen for messages from the server
|
|
|
|
@sock.on('message_from_assistant')
|
|
|
|
def on_message_from_jarvis(data):
|
|
|
|
print("Assistant says: " + data['data'])
|
|
|
|
global waiting
|
|
|
|
waiting = False
|
|
|
|
|
|
|
|
|
|
|
|
# Chat with the server
|
|
|
|
while True:
|
|
|
|
|
|
|
|
while not waiting:
|
|
|
|
message = input("Enter a message to send to the server: ")
|
|
|
|
|
|
|
|
# Exit when CTRL+C is pressed
|
|
|
|
if message == "exit":
|
|
|
|
print("Exiting")
|
|
|
|
|
|
|
|
# Leave the room
|
|
|
|
sock.emit('leave', json.dumps({'uuid': 'clientpc'}))
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
waiting = True
|
|
|
|
|
2023-11-06 21:38:13 +01:00
|
|
|
sock.emit('process_message', json.dumps({'text': message, 'uuid': 'clientpc', 'engine': 'chatgpt3'}))
|