Subject: Re: Whats the point
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2000/07/08
Newsgroups: comp.lang.scheme
Message-ID: <8k6i37$2vn2g$1@fido.engr.sgi.com>
<brlspam@sperience.com> wrote:
+---------------
| People may use the telnet program to connect to servers like this, but
| that doesn't mean the telnet protocol is used.  The telnet program does
| not try to do option negotiation, etc. unless connecting to the default
| telnet port.  For other ports, it's just a TCP connection that you can
| type to and see what comes back.
+---------------

Actually, I think the actual rule is that it doesn't try to do option
negotiation, etc. unless the connected-to port *sends* at least one
Telnet command first. You can in fact do the full Telnet protocol with
ports other than the default telnet port...

+---------------
| I'm sure most Scheme implementations have some way to get a TCP
| connection in the form of an input port and an output port.
+---------------

Yup. Almost all of them. Here's a (overly-simple, possibly buggy)
example in MzScheme:

	% cat mzd
	#!/usr/local/bin/mzscheme -r
	(require-library "mzlib.ss")
	(define (print* . x) (for-each display x) (newline))
	(define tcp-server-port 3456)

	(let ((server (tcp-listen tcp-server-port 1)))
	  (print* "[Listening on port " tcp-server-port "]") 
	  (let-values (((ip op) (tcp-accept server)))
	    (print* "[Connection accepted]")
	    (parameterize ((current-output-port op) 
			   (current-error-port op)
			   (current-input-port ip))
	      (print* "MzScheme listener -- type '(exit)' to quit")
	      (read-eval-print-loop))))
	% ./mzdaemon
	[Listening on port 3456]
	[Connection accepted]
	% 

and in another window:

	% telnet localhost 3456
	Trying 127.0.0.1...
	Connected to localhost.
	Escape character is '^]'.
	MzScheme listener -- type '(exit)' to quit
	> (+ 1 2 3)
	6
	> (exit)
	Connection closed by foreign host.
	% 

Obviously, for any app that wanted to be able to do something useful
at the same time that it was running the listener, you'd need to put
the above inside a thread [which MzScheme supports] or something...


-Rob

-----
Rob Warnock, 41L-955		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043