Arc Forumnew | comments | leaders | submitlogin
1 point by bOR_ 6018 days ago | link | parent

Hmm. still a bit puzzled. I seem able to read (in various ways readc, readline) no problem, but writing to cadr inout doesn't seem to trigger new input from the mud to read.

All of you, thanks for the help so far. I'll tinker on with it later, time for my primary arc project ;).



2 points by stefano 6017 days ago | link

For the output problem, try flushing the out stream with flush-socket on Anarki or the corresponding flush-output from mzscheme, maybe the output is written to a buffer and there is not enough information to send to force the buffer to be flushed.

-----

1 point by bOR_ 6017 days ago | link

Thanks for the flush-output thing, but it seems I will first have to work my way past the readc / peekc problem.

(avendar is down right now, so if anyone is trying to help out, use another mud / telnet server)

  arc> (readc (car inout))
  #\M
  arc> (readc (car inout))
  #\o
  arc> (readc (car inout))
  #\u
  arc> (readc (car inout))
  #\r
  arc> (readc (car inout))
  #\n
  arc> (readc (car inout))
  #\e
  arc> (readc (car inout))
  #\d
  arc> (readc (car inout))
  #\?

  arc> (peekc (car inout))
  #\space
  arc> (readc (car inout))
  #\space

  arc> (peekc (car inout))
  #\u0001
  arc> (readc (car inout))
  #\u0001

  arc> (peekc (car inout))
  user break
peekc hangs when I'm reading the output from telnet, but works fine (returning nil) when I'm reading out the output after the last char from a stored pipe.

  arc> (= answer (pipe-from "echo hello"))

  arc> (readc answer)
  #\l
  arc> (readc answer)
  #\o
  arc> (readc answer)
  #\newline
  arc> (peekc answer)
  nil
  arc> (peekc answer)
  nil
  arc> (readc answer)
  nil

-----

2 points by almkglor 6017 days ago | link

In my experience peekc doesn't seem to work properly (i.e. as advertised) at all.

I assume you're doing peekc so that you can do something else while waiting for a character? If that is what you're trying to do, I suggest you use threads:

  (let ch nil
    (thread (= ch (readc:car inout)))
    (while (no ch)
      (do-something-while-waiting))
    (do-something-with ch))

-----

1 point by bOR_ 6010 days ago | link

(waiting for a program to calculate the variation in epitope clusters, so working on this for a moment)

  (= mudpipe (tcp-connect "avendar.com" 9999))

  (def readmud ()
     (let ch nil
       (thread (= ch (readc:car mudpipe)))
       (while (no ch)
       ; wait patiently
       )
     (pr ch)
     (readmud)))

  (= mudreader (new-thread readmud))

(first time I work with threads) readmud only reads one character at a time, and I want it to just keep on writing as long as there is data. I'll try to add a thread that calls readmud again the moment it returns something sensible.

Partial success. The reading bit seems to function fine (if slow ;), and I now can use arc while in the background the muds' output is being read, but still cannot write. Did add mzscheme's flush-out (but perhaps in some wrong way. Will look at it during the next work-break ;).

-----

1 point by almkglor 6010 days ago | link

Err. If you're just waiting patiently.... why not just readc directly?

  (def readmud ()
    (pr:readc:car mudpipe)
    (readmud))

-----

1 point by stefano 6017 days ago | link

Maybe the problem with peekc is that it tries to read a character from the socket, but the server has yet to write that character, and peekc doesn't return nil because the server hasn't yet closed its output stream, so there is no end-of-file.

-----