r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Pekr
30-Apr-2005
[983x3]
More about Rebol TCP networking - http://www.rebol.com/docs/core23/rebolcore-13.html
http://www.rebol.com/docs/core23/rebolcore-14.html
http://www.rebolforces.com/
Micha
30-Apr-2005
[986x2]
rebol []

conn: make port! tcp://:80



black-lista: [ 69.64.51.223 194.69.207.145 80.252.0.145 194.69.207.165 
217.73.17.115]




adns: open/no-wait make port! dns:///async

adns/awake: func [port /local dat][                
		
		data: copy port

                print data
		
		false 
	]				

insert tail system/ports/wait-list adns





heandler: func [ port /local data dns  ]

               [ print "new connetion"

               serwer: first port

               client: make port! tcp://222.76.73.113:1080
              
               
               serwer/sub-port: client
               client/sub-port: serwer

               set-modes client [no-wait: true timeout: 00:01:00]
               set-modes serwer [no-wait: true ]

                          
 wait serwer
             
data: copy serwer



dns: to-tuple copy/part skip to-binary  data 4 4  

insert adns dns ;print dns name



either find black-lista dns [ close serwer  print "firtled" print 
read join dns:// dns ]
                           

                            [ insert serwer  join #{005A} [debase/base  skip to-hex serwer/port-id 
                            4 16 to-binary dns ] 



insert tail system/ports/timeout-list client

      open/binary client 

ping: to-integer  (0:01:00 - get-modes client 'timeout )* 1000 

  print [ "open" ping ]
                                                


                              insert client data

                              wait client

data: copy client



client/awake: :response

serwer/awake: :request

insert tail system/ports/wait-list  client


insert tail system/ports/wait-list  serwer







] 



       false         
]




request: func [ port /local data   ] 

              [ data: make string! 10000
               read-io port data 10000

                either data <> {} [ 
                                    insert port/sub-port data ] 

                            [  close port 

                              remove find system/ports/wait-list port port
                              print "close connetion serwer"

                              print length? system/ports/wait-list
                               ]

                 halt]




       
   


  
response: func [ port /local data   ] 

               [ data: make string! 10000
               read-io port data 10000

 
               either data <> {} [ 
                             insert port/sub-port data  ]

                            [  close port 

                              remove find system/ports/wait-list port port
                              print "close connetion client"

                              print length? system/ports/wait-list
                             ]

                 halt]




conn/awake: :heandler

set-modes conn [no-wait: false]

insert tail system/ports/wait-list  conn

open/direct/binary conn


print "proxy"

halt
to improve someone this promissory note maybe  ?
Tomc
30-Apr-2005
[988x2]
insert  port
without tail
Sunanda
2-May-2005
[990]
Anyone got a better way of resetting all the values in block to a 
single initial value?

Just curious, as the change/dup looks awkward --which usually suggests 
I've missed something:
     blk: [ 1 2 3 4 5 6 7 8 9]
     change/dup blk 0 length? blk
Ashley
2-May-2005
[991]
replace/all blk integer! 0
Sunanda
2-May-2005
[992x2]
Thanks!

That works only if they _are_ all integers.....But that's easily 
fixed:
     replace/all blk any-type! 0
On a related theme......Is there an easy/built-in way to check if 
all values in a series are equal?  I'm using

     all-equal?: func [ser [series!]] [ser = join next ser first ser]
As in:
    all-equal? [1 1 1 ]
    == true
    all-equal? "yyy" 
    true
    all-equal? %xxx
     true
Gabriele
2-May-2005
[994x3]
replace is mezzanine, so change/dup is going to be faster; also, 
replace is going to be much slower than the simple loop you could 
use to do what replace is doing in this specific case.
i.e. forall blk [blk/1: 0]
(compare that to the source of replace)
Volker
2-May-2005
[997]
would prefer change/dup too. both lines look equaly ugly :)
all-equal?: 1 = length? unique blk
Anton
3-May-2005
[998]
Sunanda you could use:
	1 = length? unique blk
Sunanda
3-May-2005
[999]
Thanks guys!
Micha
4-May-2005
[1000x2]
whois: func [ host /local port ][  port: make port! join tcp:// [192.149.252.44 
":43" ]


                                   port/awake: func [ port /local  ][data: copy port 


                                                      either data [  show data ]

                                                                              

                                                                 [ close port 

                                                                   remove find system/ports/wait-list port ]
                                                    
                                                      halt]



                                 insert tail system/ports/wait-list port

                                 open/no-wait port
                 

                                 insert port join "+" [ host "^/"] ]


                                   
show: func [ d /local alpha ][ 


alpha: charset [#"A" - #"Z" #"a" - #"z"]

d: find/tail  d "City:"
a: copy d
a: find/tail a alpha
a: copy/part a find a "^/"

print [ "City: " a ] 


b: find/tail d "StateProv:"
d: copy b
b: find/tail b alpha
b: copy/part b find b "^/"

print [ "StateProv: " b ]


c: find/tail  d "Country:"
c: find/tail c alpha
c: copy/part c find c "^/"

print [ "Country: " c ]   ]











whois 24.3.46.214
how to use function parse , in order to to get the  "city" , "stateProw" 
of  ,"country" , ??
Brock
4-May-2005
[1002x9]
;Micha, this should do the trick, you will be returned three variables, 
city, stateprov, and country


get-stateprov: [thru "Stateprov:  " copy stateprov to "^/" to end]
get-country: [thru "country:    " copy country to "^/" to end]
get-city: [thru "City:       " copy city to "^/" to end]

parse test [get-stateprov]
parse test [get-country]
parse test [get-city]
; actually this is better....

get-city: [thru "City:       " copy city to "^/"]
get-stateprov: [thru "Stateprov:  " copy stateprov to "^/"]
get-country: [thru "country:    " copy country to "^/" to end]

parse test [get-city get-stateprov get-country]
there is probably a better way to skip the variable number of spaces 
following the labels you are searching for, but haven't any experience 
with parse for this yet.  With what I have provided you may be able 
to get the rest to work .  I believe you can use 'any to skip multiple 
or no occurences of a parse rule
mention in...  parse test ...you should replace test with your d 
word.
in the parse rules get-city, get-stateprov; get-country, you can 
remove all of the spaces in the

thru strings ie, "City:    " can be just "City:".   Parse takes care 
of the spaces between the words.
show: func [ d /local alpha ][ 

	get-city:		[thru "City:" copy city to "^/"]
	get-stateprov:	[thru "Stateprov:" copy stateprov to "^/"]
	get-country:	[thru "country:" copy country to "^/" to end]

	parse d [get-city get-stateprov get-country]

	print [ "City: " a ] 
	print [ "StateProv: " b ]
	print [ "Country: " c ]
]
If you didn't know the order of the data being provided to you then 
you could generalize the code even further... here are the two lines 
that would change....

 get-country:	[thru "country:" copy country to "^/"]		; remove "to 
 end"

 parse d [any [get-city get-stateprov get-country] to end]	; added 
 'any block and "to end"
I WISH I WAS ABLE TO DELETE... I made a mistake <blush>, I forgot 
to remove your old variable names and there is a small error in the 
code I've posted above.
;here's a working show... but didn't easily come across a solution 
to allow for an unkown order of items to find

show: func [ d /local alpha ][ 

	get-city:	[thru "City:" copy city to "^/"]
	get-stateprov:	[thru "Stateprov:" copy stateprov to "^/"]
	get-country:	[thru "country:" copy country to "^/"]

	parse d [get-city get-stateprov get-country to end]

	print [	"City:" tab trim city newline
		"Stateprov:" tab trim stateprov newline
		"Country:" tab trim country newline
	]
]
MikeL
5-May-2005
[1011]
Brock, A good example to look at for parsing is the make-doc script. 
  Carl has updated with makedoc2.r available at this address 

http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=makedoc2.r

but it is doing what your are asking about for the make doc source 
script which can have tags

starting with === or --- followed by some text and a newline.    
The key is "rules: [some commands]"
Have a look at it.
Brock
6-May-2005
[1012]
Will do.
Gordon
6-May-2005
[1013x2]
Hello;

  I'm wondering if there is a more efficeint way to assign values directly 
  to a block of  variables.  My example involves reading lines from 
  a file and assigning them one at a time to each variable.  Here is 
  the line format:


LineFormat: [DateStr Manufacturer MF_Part TD_Part Desc Price1 Price2 
Retail Stock Misc]

Data: read/lines Filename
Str: first Data

Then I go though the String 'Str' and do the assigns

      DateStr: First Str
      Manufacturer: Second Str
      MF_Part: Third Str
      TD_Part: Fourth Str
      Desc: Fifth str
      Price1: skip Str 5
      Price2: skip Str 6
      Retail: skip Str 7
      QOH: skip Str 8
      Misc: skip Str 9


Am I missing something obvious about assigning one block of  values 
to another block of  variables?
Oops forgot a step; should be:

Data: read/lines Filename
DataStr: first data
Str: parse/all  DataStr none

(the parse splits the lines of data into a block of values)
DideC
6-May-2005
[1015x3]
SET is your friend !

	set [SatStr Manufacturer MF_part TD_Part Desc ...] Str
ie:
a: [24 "Hello" 1.2.3]
set [b c d] a
print [d c b]
Gordon
6-May-2005
[1018x2]
I'll give it a try.  Thanks  - BRB
Beauty!  Thanks DideC
DideC
6-May-2005
[1020]
no problem
Micha
7-May-2005
[1021x4]
REBOL [Title: "proxy multiple" ] 

print "start-multiple"
 list: []

proxy: make object! [ host: 24.186.191.254
                      port-id: 29992 ]

ph: func [port][ switch port/locals/events [
                          
                          connect [insert tail list  port

                                   ping: to-integer (now/time - port/date ) * 1000 
                                   port/date: now/time

                                   print [ "open   ping: " ping ]  ]

                          close [ remove find list port
                                  init

                                  ping: (now/time - port/date ) * 1000 

                                   print ["close   ping: " ping ] close port ]

                                                ]


false ]



stop: func [] [ clear system/ports/wait-list
               forall list [close first list ]]

init: func [ /local port ][ port: make port! [ scheme: 'atcp
                                               host: proxy/host

                                               port-id: proxy/port-id
                                               awake: :ph 
                                               date: now/time ]

                            open/no-wait/binary  port


                            insert tail system/ports/wait-list  port ]



set: func [ h p ] [ proxy/host: h
                    proxy/port-id: p ]
                          

send: func [ port ][ port/date: now/time

insert port join  #{0401} [debase/base  skip to-hex 80 4 16 to-binary 
193.238.73.117 #{00}] ]
plis help ?
init     error !
>> init
** User Error: No network server for atcp is specified
** Near: port: make port! [scheme: 'atcp
    host: proxy/host
    port-id: proxy/port-id
    awake: :ph
    date: now/time]
open/no-wait/binary
>>
Sunanda
7-May-2005
[1025]
Any easy way of doing this? (I got a loop, but it feels there ought 
to be a more elegant way)
     a: "123123123"
     b: "12312345678"
     print skip-common a b
     "45678"      ;; string after common part of both strings
Gordon
7-May-2005
[1026]
Hello;
  How do you convert a letter (ASCII) to it's hex equivalent?

  I've tried to-hex but it wants an integer!?  You would think it would 
  be easier than:


print to-integer to-string to-hex to-integer to-decimal to-char "a"

which works but there has got to be an easier way.
Tomc
7-May-2005
[1027]
>> to-hex to integer! #"A"
== #00000041
Sunanda
7-May-2005
[1028]
Gordon, your method only works for chars than happen to map to decimals. 
 Try this for an error:

print to-integer to-string to-hex to-integer to-decimal to-char "M"


Variant on Tom's to produce the same result as yours (may not work 
with 64-bit REBOL)
     form skip to-hex to-integer first "a" 6
Gordon
7-May-2005
[1029]
Thanks Tomc and Sunanda
Tomc
7-May-2005
[1030x2]
>> copy/part tail to-hex to integer! to char! "Z" -2
== #5A
unfortinatly for me we dont have a 64 bit rebol
Gordon
7-May-2005
[1032]
Does anyone?