我正在学习common-lisp,并且正在尝试使用usocket library编写一个使用客户机和服务器tcp套接字连接的哑巴聊天程序。下面是我的函数。
(defun receive-thread (socket)
(block receiver-nested-loop
(loop
(let ((ready-socket (usocket::wait-for-input socket)))
(let ((return-buffer (usocket::socket-receive ready-socket nil nil)))
(if (not (eq return-buffer :eof))
(handle-received-data return-buffer)
(return-from receiver-nested-loop)))))))我在两个终端上做简单的测试运行,我手动调用(main)函数(我知道如何编译和编写脚本)。
在第一个命令中(用我的ip地址替换x):sbcl --load chat.lisp -a xxx.xx.xxx.xx -s
在第二个代码中: sbcl --load chat.lisp -a xxx.xx.xxx.xx
当我的程序到达上面的函数时,我得到了以下错误:
debugger invoked on a SIMPLE-ERROR in thread
#<THREAD RUNNING {10069DF743}>:
There is no applicable method for the generic function
#<STANDARD-GENERIC-FUNCTION USOCKET:SOCKET-RECEIVE (1)>
when called with arguments
(#<USOCKET:STREAM-SERVER-USOCKET {10069DF673}> NIL NIL).下面是我的完整代码的pastebin。
有人能帮我找出我做错了什么吗?我需要做些什么来弥补它?
编辑:删除程序中多余的‘:’并重新测试。行为和错误保持不变。所有的函数调用都是导出的符号,我只是出于c++的本能。
发布于 2018-07-28 06:29:36
你发布的错误提示你错误地使用了usocket:socket-receive (稍微清理了一下):
There is no applicable method for the generic function
USOCKET:SOCKET-RECEIVE
when called with arguments
USOCKET:STREAM-SERVER-USOCKETDocumentation for this function表示,usocket:socket-receive将“从数据报套接字接收数据”。我怀疑您尝试读取的套接字是TCP套接字,而不是UDP套接字。
https://stackoverflow.com/questions/45642897
复制相似问题