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

[REBOL] Port probing Re:(4)

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--