[REBOL] Re: retrieving data from TCP port
From: gscottjones:mchsi at: 21-Oct-2002 17:43
From: Francois Prowse
> Just wondering if anyone can help me with the following...I'm sending some
> xml statements directly to a known TCP port as follows...
..
http://www.escribe.com/internet/rebol/m26710.html
Hi, Francois,
Assuming I understand the problem correctly, with just a minor change, you
may be able to simplify things considerably. Here is the quickest version
that *may* do the job:
;open a port named port
port: open tcp://x.x.x.x:3221
;let the word initial contain the sample xml
initial: read %initial.xml
;cram the xml into the port
;**note that a return value is _not _
; checked from this statement
insert port initial
;assuming server is very fast, simply read the return
; (it is usually hazardous to assume anything, though)
result: copy port
;close the port
close port
;check returned result for a unique fragment
; suggesting success or failure
either find result "</rpc-reply>" [
print "success!!"
][
print "ooh, got an error..."
]
If the port times out, or you get mysterious errors, or you want safer code,
then you may need to approach the problem differently, possibly use an
asynchronous
mode (the no-wait option) and continue polling until you
receive a none (similar to what you were doing in your code). I would have
to experiment to with a live example to get it to work right, but it would
be something like:
port: open tcp://x.x.x.x:3221
initial: read %initial.xml
insert port initial
result: copy ""
portion: copy ""
while [portion: copy port] [append result portion]
close port
either find result "</rpc-reply>" [
print "success!!"
][
print "ooh, got an error..."
]
I *hope* that helps. It helps to have a working server to try the code
against (I'm not good enough to see all the silly errors I may do on first
coding :-).
--Scott Jones