Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

retrieving data from TCP port

 [1/8] from: francois::prowse::alcatel::co::nz at: 22-Oct-2002 10:29


Hi all, Just wondering if anyone can help me with the following...I'm sending some xml statements directly to a known TCP port as follows... port: open tcp://x.x.x.x:3221 I load some xml in... initial: read %initial.xml then send it to the open port (While capturing the result...I think) result: insert port initial I can see that result: now has some data stored in it from the open port, however the port isn't open long enough to allow capturing all the returned information. So, now my question - how do I do somthing like this... while [result: copy port] [insert port initial] I need this to stay open until either of two (text) results are returned from the remote device....like this (I'm not much of a programmer here:) while result <> "error" or "</rpc-reply>" then insert port initial Hopefully you guys understand this.....as all I want to retrive is the returned XML starting with <rpc-reply> and ending with </rpc-reply> (which will either be success or have error returned) and nothing else... I'll leave it at that for the time being :) Any help appreciated Francois

 [2/8] 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

 [3/8] from: francois:prowse:alcatel at: 22-Oct-2002 12:15


hmmm, all looks good to me...however
>> result: copy port
** Access Error: Network timeout ** Where: halt-view ** Near: result: copy port
>>
I'll have to fire up tcpdump and see if data is really comming back in....either that or adjust the time outs. What does copy wait for before terminating/closing the port Francois

 [4/8] from: petr:krenzelok:trz:cz at: 22-Oct-2002 7:37


[Francois--Prowse--alcatel--co--nz] wrote:
>hmmm, all looks good to me...however >>>result: copy port
<<quoted lines omitted: 7>>
>terminating/closing the port >Francois
'copy wait for RST or FIN packet imo, or new data arrival. In sync mode, you exit the loop either by retrieving new data on the port, getting port closed by remote side, or receiving timeout on port ... I don't like sync mode and I use /no-wait mostly ... -pekr-

 [5/8] from: gscottjones:mchsi at: 22-Oct-2002 5:54


Hi, Francois, From: Francois Prowse
> hmmm, all looks good to me...however > > >> result: copy port > ** Access Error: Network timeout > ** Where: halt-view > ** Near: result: copy port > >>
Bummer.
> I'll have to fire up tcpdump and see if data is > really comming back in....either that or adjust the > time outs.
May not be a need to fire up tcpdump nor adjust the time outs. My program samples suffer from not being able to test a nd adjust. Of course, if you want to fire up tcpdump, then fire away! :-)
> What does copy wait for before terminating/closing the port
I may not be able to provide the best answer to this question. Basically copy is waiting for a none to be returned, but in my first example, it tried to read the response in one chunk, didn't receive the right signal. So copy stalls on the port. Everything stays open, and finally the network connection times out. I suspect a tcp/port-ologist could give a much better answer (in fact my dog on a bad day could probably give a better answer ;-). What we need is the no-wait refinement and loop that will catch fragments until the port finally returns a none (I have never figured out how anything can "receive" a "none"; I guess it is like the sound of one hand clapping. ;-) Try this variation: initial: read %initial.xml port: open/no-wait tcp://x.x.x.x:3221 insert port initial fragment: copy "" result: copy "" while [ wait port fragment: copy port ] [append result fragment] close port either find result "</rpc-reply>" [ print "success!!" ][ print "ooh, got an error..." ] If that doesn't work, then, yes, I would be happy to try a direct connection to a machine of your choosing. My guess is that the server might be line oriented, and that adding a /lines refinement would help. Again, just a guess... Good luck! --Scott Jones

 [6/8] from: francois:prowse:alcatel at: 23-Oct-2002 12:43


Well, in the end I've used a combination of everything suggested and come up with this. port: open/lines tcp://x.x.x.x:3221 initial: read %initial.xml getconf: read %getconf.txt insert port initial insert port getconf result: copy port portion: copy "" while [portion: copy port] [append result portion] insert port unlock close port either find result "</rpc-send>" [ print "success!!" ][ print "ooh, got an error..." ] note, on this version I've used the /lines extension of the open command. Now in result I have alot of XML .... now what to do with this. If I pass it through parse-xml I get a rebol block, which is fine, however all these "none" entries appear through it Cheers Francois

 [7/8] from: gscottjones:mchsi at: 22-Oct-2002 20:21


From: Francois Prowse
> Well, in the end I've used a combination of everything > suggested and come up with this.
...
> note, on this version I've used the /lines extension of the > open command. Now in result I have alot of XML .... > now what to do with this. If I pass it through parse-xml I > get a rebol block, which is fine, however all these "none" > entries appear through it
Hi, Francois, So, pardon my ignorance, but do you have what you need? Hoping you do ... --Scott Jones

 [8/8] from: francois:prowse:alcatel at: 23-Oct-2002 15:51


Well, it is a good start....got this part of the small script working, but parsing the XML seems to be odd. Will keep you posted. Francois

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted