[plt-scheme] Beginner-friendly Net access functions?

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Tue Jun 20 11:17:03 EDT 2006

On Tue, 20 Jun 2006, Stephen Bloch wrote:

> Are there any library functions for net communication that have really 
> simple interfaces, suitable for first-semester programming students?  I 
> recall somebody talking about a classroom exercise in which students 
> could send messages to one another, but now I can't find that discussion 
> in my files.

Hi Stephen,

I remember seeing Shriram's notes on network programming.  Let me see if I 
can find it.


> And it should be simple to open a specified URL as an input 
> port.

Here's a small snippet of code to do so:

(require (lib "url.ss" "net"))

;; open-url: string -> input-port
;; Opens up a URL and returns an input port for the resource.
(define (open-url url-string)
   (get-pure-port (string->url url-string)))

For example:

> (read-line (open-url "http://plt-scheme.org/"))
"<html><head><title>PLT Scheme</title><meta name=\"generator\" 
content=\"PLT Scheme\" /><meta http-equiv=\"Content-Type\" 
content=\"text/html; charset=utf-8\" /><link rel=\"icon\" 
href=\"http://www.plt-scheme.org/plticon.ico\" type=\"image/ico\" /><link 
rel=\"shortcut icon\" href=\"http://www.plt-scheme.org/plticon.ico\" 
/><style type=\"text/css\">"

Best of wishes!

Posted on the users mailing list.