Todd Daugherty's Official Board
Playing with AI - Printable Version

+- Todd Daugherty's Official Board (http://160.32.227.211/n9ogl)
+-- Forum: General (http://160.32.227.211/n9ogl/forumdisplay.php?fid=1)
+--- Forum: Main Board (http://160.32.227.211/n9ogl/forumdisplay.php?fid=2)
+--- Thread: Playing with AI (/showthread.php?tid=548)



Playing with AI - admin - 02-26-2026

A multi-channel text-based P2P chat program


  1. Import the required libraries:
Quote:import socket
from threading import Thread, Lock


  1. Create server and client sockets:
Quote:HOST, PORT = 'localhost', 12345
# Server
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((HOST, PORT))
server_socket.listen()
print(f"Server listening on {HOST}:{PORT}")
# Client
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST, PORT = 'localhost', 12345
client_socket.connect((HOST, PORT))


  1. Implement a function to handle each client connection:
Quote:def handle_client(client_socket):
    while True:
        try:
            data = client_socket.recv(1024).decode('utf-8')
            print(data)
            # Send response back to the client
            response = input(f"Enter response for {data}: ")
            client_socket.send(response.encode('utf-8'))
        except Exception as e:
            print(e)
            break
    client_socket.close()


  1. Create a function to manage multiple clients:
Quote:def handle_connections(server_socket):
    connections = []
    lock = Lock()
    while True:
        client_socket, addr = server_socket.accept()
        print(f"Connected by {addr}")
        # Add the new connection to our list of connections
        with lock:
            connections.append(client_socket)
        # Start a new thread for each connected client
        client_thread = Thread(target=handle_client, args=(client_socket,))
        client_thread.start()

  1. Implement the main server loop to handle multiple clients:
Quote:def main():
    server_socket = create_server_socket()
    handle_connections(server_socket)
if __name__ == "__main__":
    main()



RE: Playing with AI - admin - 02-27-2026

been playing with AI going to put an AI chat bot online that you can communicate. Been experimenting with it, going work on the character background and lore. I might just put a different one on and let it loose.