Paste: socket client

Author: josh
Mode: factor
Date: Sat, 28 Feb 2009 03:49:17
Plain Text |
! Copyright (C) 2009 Your name.
! See http://factorcode.org/license.txt for BSD license.

USING: kernel threads io io.sockets io.encodings.utf8 prettyprint math ;
IN: mudclient

: setup-streams ( object object -- object ) <inet> utf8 <client> 
   drop
   dup 
   [ 
      [ 
         [ [ print "hello" print ] each-line t ] loop
      ] with-input-stream 
   ] curry "input-thread" spawn 
   drop
;

: read-keyboard-loop ( object -- object )
!   dup
   [
      [ 
         [ yield readln dup [ write flush ] [ drop ] if t ] loop
      ] with-output-stream 
   ] curry "output-thread" spawn 
 ;

: runme ( -- object ) 
 "mud.arctic.org" 2700 setup-streams read-keyboard-loop ;

MAIN: runme

! [ [ print ] each-line ] with-client ;
! type "IN: mudclient" in listener first, then f2
! ./factor -run=mudclient

New Annotation

Summary:
Author:
Mode:
Body: