Clozure Common Lisp-TCP套接字编程-发送答复 [英] Clozure Common Lisp - TCP Socket Programming - Sending a Reply

查看:104
本文介绍了Clozure Common Lisp-TCP套接字编程-发送答复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常小的程序,可以打开一个套接字并接受连接。然后,它将获取远程IP和端口。

I have a very small program which opens a socket and accepts a connection. It then grabs the remote IP and port.

我想向远程计算机(远程登录)发送短信并关闭连接。

I'd like to send a text message to the remote computer (telnet) and close the connection.

我无法确定哪个功能是向telnet客户端发送消息。

I can't determine which function is for sending a message to the telnet client.

《手册》 列出了一个名为发送至的函数,但它说它是用于UDP套接字的,我正在使用TCP套接字。

The Clozure manual lists a function called "send to" but it says it's for UDP sockets and I'm working with TCP sockets.

我希望有人可以告诉我适当的功能是什么,或者,如果发送到是适当的功能,如何使用

I hope someone can tell me what the proper function is, or, if "send-to" is the proper function, how to use it properly.

谢谢

(setq my-socket (ccl:make-socket :connect :passive :format :text
        :local-port 20000 :reuse-address t))

(setq connection (ccl:accept-connection my-socket))

(setq remote-host (ccl:remote-host connection))

(setq remote-port (ccl:remote-port connection))


推荐答案

CCL:ACCEPT-CONNECTION的文档说它返回一个流。

The documentation of CCL:ACCEPT-CONNECTION says that it returns a stream.

因此您可以使用该流的Common Lisp的常规I / O操作(例如:PRINC)。有关I / O操作,请参见有关流和打印机的HyperSpec章节。

So you can use the normal I/O operations (example: PRINC) of Common Lisp with that stream. For I/O operations see the HyperSpec chapters on 'streams' and the 'printer'.

(defun st (port)
  (ccl:with-open-socket (socket :connect :passive
                                :format :text
                                :local-port port
                                :reuse-address t)
    (with-open-stream (stream (ccl:accept-connection socket))
      (princ "CCL example response" stream))))

; example call
(st 20000)

这篇关于Clozure Common Lisp-TCP套接字编程-发送答复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆