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

Port probing

 [1/9] from: ptretter:charter at: 16-Oct-2000 22:12

If I have to ports that I wait for data on how can I put them in a while or forever loop without locking up the console. If I had a if statement testing data received.

 [2/9] from: al:bri:xtra at: 16-Oct-2000 20:40

> If I have two ports that I wait for data on how can I put them in a while
or forever loop without locking up the console. If I had a if statement testing data received. How about opening the console as a port and include it in your wait? You'll need to check after the 'wait, to see if the event was a key or stuff from your other ports. Andrew Martin Turning it all inside out... ICQ: 26227169

 [3/9] from: holger:rebol at: 16-Oct-2000 20:41

On Mon, Oct 16, 2000 at 10:12:13PM -0500, [ptretter--charter--net] wrote:
> If I have to ports that I wait for data on how can I put them in a while or > forever loop without locking up the console. If I had a if statement > testing data received.
That depends on the type of port and the version of REBOL you use. Assuming tcp, udp or serial ports opened with /direct, you can wait for multiple ports with wait [port1 port2] which returns one of the ports if it has data, none otherwise. To get a block of all ports returned instead of just a single port use wait/all (latest experimental version only). To just poll ports without blocking add a timeout of zero, i.e. try wait [port1 port2 0] Using a timeout of zero to poll only works with some old (pre-2.3) versions of REBOL (on some platforms) and with the latest experimental versions (on all platforms), but not with REBOL 2.3. Other types of ports currently do not support 'wait. Higher-level network ports (HTTP etc.) will probably support it in one of the next experimental versions, when opened with /direct. You may also want to look at the no-wait refinement for 'open. It guarantees that 'copy on a port never blocks, even if there is no data available on it (latest experimental version only). -- Holger Kruse [holger--rebol--com]

 [4/9] from: ptretter:charter at: 17-Oct-2000 8:05

Thanks Holger for the great feedback. I am gonna test this shortley to see if it accomplishes what I'm trying to do. I will post to the list what I find. Paul Tretter

 [5/9] from: ptretter:charter at: 17-Oct-2000 8:09

How do you open a console as a port? Paul Tretter

 [6/9] from: ptretter:charter at: 17-Oct-2000 10:55

I tried play with this with this script while opening another console and inserting to those ports. I got no expected output. The core docs need to be updated to explain listening on more than one port. REBOL[] port1: open tcp://:55 port2: open tcp://:56 while [true][ wait [port1 port2 0] buffer1: first port1 buffer2: first port2 print buffer1 print buffer2 ]

 [7/9] from: jschuhr:ho:tmail at: 17-Oct-2000 12:11

How does the "view" function handle calls to other functions? I have the following scenario: testserver.r +------------------------------------ REBOL [ title "Test Server" ] system/console/busy: none start-server: func [] [ server-port: open tcp://:8001 forever [ connection-port: first server-port wait connection-port data-recvd: copy connection-port if data-recvd <> none [ print data-recvd ] close connection-port clear data-recvd wait 00:00:01 ] ] view layout [ button "Startup" [start-server] button "Shutdown" [quit] size 200x200 ] +--------EOF--------------------------- testclient.r +-------------------------------------- REBOL [] send-message: :save view layout [ button "Send message" [ send-message tcp://localhost:8001 "Message test" ] button "Exit" [quit] ] +----------EOF------------------------- The testserver.r starts and the window shows up. The user clicks on "Start server" and the server starts listening for messages. The testclient.r starts up and the user and send test messages by clicking on the button and as expected, the server displays the messages. However, at this point, REBOL/View isn't interactive anymore for the testserver.r reblet. How does blocking on a port affect View and how can one listen on a port and maintain interactivity in the window? --John
>From: [ptretter--charter--net] >Reply-To: [list--rebol--com]
<<quoted lines omitted: 50>>
>Holger Kruse >[holger--rebol--com]
_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at Share information about yourself, create your own public profile at

 [8/9] from: allen::rebolforces::com at: 18-Oct-2000 8:49

This is a multi-part message in MIME format. ------=_NextPart_000_0051_01C038E0.5B969980 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi John, You need to also add a port for view events. Using 'dispatch makes it easier to react to different ports. See note below about the attached script. ? dispatch USAGE: DISPATCH port-block DESCRIPTION: Wait for a block of ports. As events happen, dispatch port handler blocks. DISPATCH is a function value. ARGUMENTS: port-block -- Block of port handler pairs (port can be timeout too). (Type: block) ;--------------------------------- The attached View script communicates a message to each member in its client list. To use... Run 3 instances of the script and set the port numbers to 8001, 8002, 8003 Now anything you type in one will show in the other two. Hope this script helps someone. Cheers, Allen K ------=_NextPart_000_0051_01C038E0.5B969980 Content-Type: text/x-rebol; name="peer chat.r" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="peer chat.r" REBOL [ Title: "View Peer Chat Demo" Author: "Allen Kamp" Purpose: "Simple peer-to-peer chat in View" status: "prototype" ] ;comments start of DirectPlay like gaming subsystem system/options/quiet: true system/console/busy: none host-address: does [system/network/host-address] host: does [system/network/host] clients: reduce [ host-address "8001" host-address "8002" host-address "8003" ] my-address: host-address port-num: 8001 message-port: none ; for view events event-port: open [scheme: 'event] set-message-port: func [ Changes Port Address of Connection port-id ][ if port? message-port [close message-port] message-port: open/direct join tcp:// [":" port-id] ] do-message: func [/local data newline? type address][ if none? data: copy first message-port [close message-port return 'break] newline?: does [either empty? converse/text [""][newline]] set [type address data] parse/all data "#" if data = "quit" [close message-port close event-port quit] append tail converse/text join newline? [address " - " data] show converse ] do-event: func [/local event][ event: first event-port if event/type = 'close [quit] do event ] tell-all: func [list [block!] data][ foreach [ip port-id] list [ if error? try [tell ip port-id data][print ["Error - No Connection" ip port-id]] ] ] tell: func [ip port-id data /local client][ client: open rejoin [tcp:// ip ":" port-id] insert client rejoin ['msg "#" ip ":" message-port/port-id "#" data] close client ] view/new layout [ across client-ip: txt join "IP " host-address navy 200 bold server-ip: field form port-num button "Set Port" [set-message-port server-ip/text] return converse: area 516 with [para: [wrap?: true]] v1: slider to-pair reduce [16 converse/size/y][scroll-para converse face] return below msg: field 516 button #"^M" "send" [ tell-all clients copy msg/text system/view/caret: head clear msg/text show msg ] ] set-message-port port-num dispatch [ message-port :do-message event-port :do-event ] ------=_NextPart_000_0051_01C038E0.5B969980--

 [9/9] from: al:bri:xtra at: 18-Oct-2000 0:55

> How do you open a console as a port?
Try page 573 Appendix C-5 of the Rebol Core manual core.pdf. Andrew Martin ICQ: 26227169

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