Arc Forumnew | comments | leaders | submitlogin
Outgoing sockets
8 points by twilightsentry 5636 days ago | 2 comments
Vanilla arc3 has the 'open-socket and 'socket-accept functions for receiving connections. This hack defines 'socket-connect to establish outgoing connections.

(socket-connect host port) => (in-stream out-stream)

Also, 'flushout is extended to deal with ports other than (stdout). That's not strictly necessary, but useful if you're sending data with 'writec or 'writeb.

(flushout (o out-stream (stdout)))

Usage example:

  (let (in out) (socket-connect "www.google.com" 80)
    (w/stdout out
      (prn "GET /index.html HTTP/1.0")
      (prn "Host: www.google.com")
      (prn))
    (while (prn:readline in))
    (close in out))
Patch is at: http://twilightsentry.org/hacks/socket-connect.patch


1 point by garply 5597 days ago | link

Thanks for this - do you think maybe this (or some form of this) should go into the nex3 repo? Ability to make outgoing connections seems pretty important for a language.

-----

1 point by rntz 5596 days ago | link

Done.

-----