Network Port Reading Problem
[1/5] from: rsnell::webtrends::com at: 7-Sep-2000 15:18
I need to implement a telnet client in Rebol for a fixed task (that is, I
don't
want a terminal type thing - all client commands are fixed and will be run
with no user interaction).
Anyway, so I open up a telnet connection to the box of interest:
>> c: open tcp://192.168.15.233:23
>>
Cool. Now in this particular case, the telnet server returns an IAC packet
asking me
to DO (telnet parlance) some option stuff. My question is - how do I get
the data
that the server has sent me? I try:
>> print copy c
..... finally get network timeout
or
>> print first c
..... finally get network timeout
In my sniffer I see that there IS definitely data sent to me over the open
telnet socket
and the telnet server is waiting for me to get it and respond. If I sniff
the Win32 built-in
telnet client I see that the client do the right thing and respond to this
packet.
What am I not doing correct here to get this data?
TIA,
Rodney
[2/5] from: holger:rebol at: 7-Sep-2000 15:46
On Thu, Sep 07, 2000 at 03:18:38PM -0700, [rsnell--webtrends--com] wrote:
> I need to implement a telnet client in Rebol for a fixed task (that is, I
> don't
> want a terminal type thing - all client commands are fixed and will be run
> with no user interaction).
Try something like this. Only works with current experimental versions of
REBOL (www.rebol.com/xpers/xpers.html) though.
peer: open/direct/binary/no-wait tcp://myhost:23
forever [
wait peer
input-data: copy peer
; Handle your data here and insert the response, e.g.
; insert peer #{fffc25}
; The following print is just an example...
print input-data
]
The direct/no-wait ensures that copy returns whatever data is available. Without
it copy usually blocks until the peer signals end-of-file. The wait is necessary
to avoid busy-looping on copy. If copy returns an empty series (#{}) then this means
no data is available (should not happen after a wait). If copy returns none then the
peer has closed the connection.
--
Holger Kruse
[holger--rebol--com]
[3/5] from: ptretter:charter at: 7-Sep-2000 18:05
Im having the same problem. Need more information in the documentation
about actively exchange data as in telnet type connection. Instead the docs
seem to just state how to insert and open a port or exchange a bit of
information. I want to keep the active session and I cant see the data
coming from my connection. I can see it with telnet and know its coming.
[4/5] from: rsnell:webtrends at: 7-Sep-2000 16:42
Thanks Holger. I'll try the xper but I really need to stick
with a stable release at this point. It looks like I can use
the /binary refinement and copy/part to get the data and that
should work for now.
One possible problem I saw though. I want to check whether there
is data waiting on the port before trying to copy. I see the
users guide says to use 'wait like [wait c 1] to wait on
port c for 1 second. However, if I do the following:
>> c: open/binary tcp://host:23
>> print copy/part c 100
>> #{FFFD18FFFD1FFFFD23FFFD27FFFD24}
>> wait c 1 ;should return after 1 second because there is no more data
/ (never returns from waiting)
It doesn't seem like wait is working correctly.
Basically I need something like the select() socket function.
Am I doing the right thing here?
Thanks again,
Rodney
[5/5] from: holger:rebol at: 7-Sep-2000 17:30
On Thu, Sep 07, 2000 at 04:42:53PM -0700, [rsnell--webtrends--com] wrote:
> >> wait c 1 ;should return after 1 second because there is no more data
> / (never returns from waiting)
Try wait [c 1]
--
Holger Kruse
[holger--rebol--com]