;// rmClient.lsp is a client that interacts with Sam, a checkers server. ;// given the correct machine name for the server, a user id, and a password ;// (server, user, and password in the let), (client) will initiate connection ;// and start a game with the default player. ;// ;// the program has been tested and used under CLISP, but should work with ;// other common lisp implementations. ;// ;// Copyright (C) 2008 Robert McCartney ;// This program is free software; you can redistribute it and/or ;// modify it under the terms of the GNU General Public License as ;// published by the Free Software Foundation; either version 2 of the ;// License, or (at your option) any later version. ;// This program is distributed in the hope that it will be useful, but ;// WITHOUT ANY WARRANTY; without even the implied warranty of ;// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;// General Public License for more details. ;// You should have received a copy of the GNU General Public License ;// along with this program; if not, write to the Free Software ;// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ;// USA (defun client () (let ((server "machinename.engr.uconn.edu") ;; put correct machine here (port 3499) (user "99") ;; put user id here (password "2344323") ;; put password here (opponent "0")) (with-open-stream (socket (connect-to-server server port)) (read-message-echo socket); start message (read-message-echo socket); // ID query (write-message-echo user socket); // user ID (read-message-echo socket); // password query (write-message password socket); // password (read-message-echo socket); // opponent query (write-message-echo opponent socket); // opponent (read-message-echo socket); // game (read-message-echo socket); // color (read-message-echo socket); ))) (defun connect-to-server (server port) (socket:socket-connect port server)) (defun write-message (message socket) (format socket (add-cr-nl message))) (defun write-message-echo (message socket) (format socket (add-cr-nl message)) (format t "~s~%" message)) (defun read-message-echo (socket) (setq rv (read-line socket)) (format t "~s~%" rv) rv) (defun add-cr-nl (message) (with-output-to-string (s) (format s message) (write-char #\Return s) (write-char #\Newline s)))