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

Port Problems again

 [1/2] from: ptretter:charter at: 24-Oct-2000 14:59


Doesnt work for me. If I open another script and try to insert port somedata to those ports it doesnt work. Can anyone else tell me or show me a script where they have got it to work. Paul Tretter --------------------------------------------------------- REBOL[] port1: open/direct/lines tcp://24.217.21.225:55 port2: open/direct/lines tcp://24.217.21.225:56 while [true][ dispatch [ port1 [print "port1 awake"] port2 [print "port2 awake"] ] print "hello" if buffer1 <> none [print buffer1] if buffer2 <> none [print buffer2] ] halt

 [2/2] from: al::bri::xtra::co::nz at: 25-Oct-2000 22:52


Hi, Paul. You wrote:
> Can anyone else tell me or show me a script where they have got it to
work. I don't know if this will help or not, but this script works for my Rebol Webserver/Wiki/Sparrow. Please ignore the really horrible part at the core, but it does work! Currently, this script can deliver my entire hard disk into my browser, and create rather boring html pages if I surf to a file that doesn't exist. I also discovered an interesting "feature" in my browser with respect to relative page locations and frames, possibly a bug in MSIE5.5. I hope this helps somewhat. BTW, .RSP is going to stand for Rebol Server Pages... Andrew Martin Now that I've written my Rebol Webserver,... where's the line for Jedi Masters? :-) ICQ: 26227169 http://members.nbci.com/AndrewMartin/ -><- [ Rebol [ Name: 'Webserver File: %Webserver.r Title: "Webserver" Component: 'Webserver Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 25/October/2000 Purpose: "Serves web pages" Version: 1.9.0 History: [ 1.9.0 {Added check for %index.html file.} 1.8.0 {Sorted directory listings.} 1.7.0 {Added Print-Request refinement to trigger printing of Requests.} 1.6.0 {Added check for going higher than root to 'Get.} 1.5.0 {Added 'try to reads.} 1.4.0 {Added 'Web [file!] to 'Not-Found function.} 1.3.0 {Improved Directory display.} 1.2.0 {Clickable list of filenames in 'Get-Directory. More Mime-Types and a default Mime-Type.} 1.1.0 {'Webserver clear 'Stop flag to 'false as clearly caller is wanting to start again.} 1.0.0 "Original" ] ] do %../HTML/HTML.r Webserver!: make object! [ Mime-Types: [ %.AA "application/x-AA" %.AIF "audio/aiff" %.AIFF "audio/aiff" %.AIFC "audio/aiff" %.AU "audio/basic" %.AVI "video/avi" %.BMP "image/bmp" %.class "application/x-java" %.CSS "text/css" %.EBO "application/x-EBO" %.EXE "application/x-msdownload" %.FDF "application/vnd.fdf" %.gif "image/gif" %.htm "text/html" %.html "text/html" %.ICO "image/x-icon" %.jpg "image/jpeg" %.jpeg "image/jpeg" %.jpe "image/jpeg" %.js "application/x-javascript" %.LIT "application/x-OBAK" %.MPG "video/mpeg" %.MP2 "video/mpeg" %.MP3 "audio/mpeg" %.MPE "video/mpeg" %.MPEG "video/mpeg" %.M1V "video/mpeg" %.MP3 "audio/mpeg" %.pdf "application/pdf" %.PNG "image/png" %.PS "application/postscript" %.EPS "application/postscript" %.r "text/x-rebol" %.RB "application/x-rocketbook" %.RMI "audio/mid" %.MID "audio/mid" %.MIDI "audio/mid" %.SND "audio/basic" %.TIF "image/tiff" %.TIFF "image/tiff" %.txt "text/plain" %.WAV "audio/wav" %.XML "text/xml" %.XSL "text/xml" ] Mime-Type: function [Filename [file!]] [Mime] [ all [ not found? Mime: select Mime-Types find Filename "." Mime: "application/x-msdownload" ] Mime ] Not-Found: func [Connection [port!] Web [file!] Filename [file!]] [ insert Connection rejoin [ "HTTP/1.0" " " "404 Not Found" newline "Content-type:" "text/html" newline newline HTML [ title "404 Not Found" body h1 "Error - 404 Not Found" "File not found!" ] ] ] Forbidden: func [Connection [port!]] [ insert Connection rejoin [ "HTTP/1.0" " " "400 Forbidden" newline "Content-type: " "text/html" newline newline HTML [ title "400 Forbidden" body h1 "Error - 400 Forbidden" "Forbidden!" ] ] ] Post: func [Connection [port!] Request [string!]] [ Serve Connection "text/html" reduce [ HTML [ title "Request" body h1 "Request" pre Request ] ] ] Get-Directory: function [Connection [port!] Web [file!] Directory [file!]] [Files] [ if error? try [ Files: read clean-path join Web Directory ][ Forbidden Connection exit ] Serve Connection "text/html" reduce [ HTML [ title join "Directory: " form Directory body h1 join "Directory: " form Directory list map sort Files func [Filename] [ a join Directory Filename form Filename ] ] ] ] Get-File: function [Connection [port!] Filename [file!]] [Data] [ either error? try [Data: read/binary Filename] [ Forbidden Connection ][ Serve Connection Mime-Type Filename Data ] ] Get: function [Connection [port!] Web [file!] Filename [file!]] [Absolute] [ Absolute: clean-path join Web Filename ifs/default [ not found? find Absolute Web [ Forbidden Connection ] not exists? Absolute [ Not-Found Connection Web Filename ] dir? Absolute [ Filename: join Absolute %index.htm if exists? Filename [ Get-File Connection Filename ] Filename: join Absolute %Index.html if exists? Filename [ Get-File Connection Filename ] Get-Directory Connection Web Filename ] ][ Get-File Connection Absolute ] ] Serve: func [Connection [port!] Mime [string!] Data] [ write-io Connection Data: append rejoin [ "HTTP/1.0" " " "200 OK" newline "Content-type: " Mime newline newline ] Data length? Data ] Stop: false set 'Webserver function [ "Serves Webpages." Port [integer!] Web [file!] /Print-Request ][ Listen Connection Request Filename ][ Listen: open/lines join tcp://: Port Stop: false while [not Stop] [ Connection: first wait Listen Request: make string! 1024 repend Request [first Connection newline] while [not 1 = length? Connection/state/inBuffer] [ repend Request [first Connection newline] ] if Print-Request [print Request] ifs/default [ parse Request [thru "POST " to end] [ Post Connection Request ] parse Request [thru "GET " copy Filename to " HTTP" to end] [ Filename: to-file replace/all Filename " " " " Get Connection Web Filename ] ][ Forbidden Connection ] close Connection ] close Listen ] ] ] [ Rebol [ Name: 'Spider File: %Spider.r Title: "Spider" Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 25/October/2000 Purpose: "In place editing of web pages" Version: 1.1.0 History: [ 1.1.0 {Put in Print-Request refinement.} 1.0.0 "Original" ] ] secure allow do %../Webserver/Webserver.r print rejoin [ system/script/title ", version: " system/script/header/version "." newline {Press "Esc" key to stop.} ] Port: 7777 Sparrow: make object! [ Edit: HTML!/Fragment [ a %/Edit.rsp image %/Edit.gif 14x11 "Edit" ] Editing: HTML!/Fragment [ a %/Editing.rsp image %/Editing.gif 11x7 "Editing" ] Add: HTML!/Fragment [ a %/Add.rsp image %/Add.gif 9x8 "Add" ] Link: HTML!/Fragment [ a %/Link.rsp image %/Link.gif 12x10 "Link" ] ] Supercede: func [Object [object!] Block [block!]] [ do bind Block in Object 'self ] Supercede Webserver! [ Not-Found: function [Connection [port!] Web [file!] Filename [file!]] [Page] [ Page: HTML [ title join "[" [ Filename "]" ] body h1 [Sparrow/Edit join "[" [ Filename "]" ]] Sparrow/Add ] if error? try [ write clean-path join Web Filename Page Serve Connection "text/html" Page ][ Forbidden Connection ] ] ] browse join http://localhost: [Port "/" ] Webserver/Print-Request Port %/c/Rebol/Spider/Web ; Webserver/Print-Request Port %/c ] -- Attached file included as plaintext by Listar -- -- File: Webserver.r [ Rebol [ Name: 'Webserver File: %Webserver.r Title: "Webserver" Component: 'Webserver Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 25/October/2000 Purpose: "Serves heb pages" Version: 1.9.0 History: [ 1.9.0 {Added check for %index.html file.} 1.8.0 {Sorted directory listings.} 1.7.0 {Added Print-Request refinement to trigger printing of Requests.} 1.6.0 {Added check for going higher than root to 'Get.} 1.5.0 {Added 'try to reads.} 1.4.0 {Added 'Web [file!] to 'Not-Found function.} 1.3.0 {Improved Directory display.} 1.2.0 {Clickable list of filenames in 'Get-Directory. More Mime-Types and a default Mime-Type.} 1.1.0 {'Webserver clear 'Stop flag to 'false as clearly caller is wanting to start again.} 1.0.0 "Original" ] ] do %../HTML/HTML.r Webserver!: make object! [ Mime-Types: [ %.AA "application/x-AA" %.AIF "audio/aiff" %.AIFF "audio/aiff" %.AIFC "audio/aiff" %.AU "audio/basic" %.AVI "video/avi" %.BMP "image/bmp" %.class "application/x-java" %.CSS "text/css" %.EBO "application/x-EBO" %.EXE "application/x-msdownload" %.FDF "application/vnd.fdf" %.gif "image/gif" %.htm "text/html" %.html "text/html" %.ICO "image/x-icon" %.jpg "image/jpeg" %.jpeg "image/jpeg" %.jpe "image/jpeg" %.js "application/x-javascript" %.LIT "application/x-OBAK" %.MPG "video/mpeg" %.MP2 "video/mpeg" %.MP3 "audio/mpeg" %.MPE "video/mpeg" %.MPEG "video/mpeg" %.M1V "video/mpeg" %.MP3 "audio/mpeg" %.pdf "application/pdf" %.PNG "image/png" %.PS "application/postscript" %.EPS "application/postscript" %.r "text/x-rebol" %.RB "application/x-rocketbook" %.RMI "audio/mid" %.MID "audio/mid" %.MIDI "audio/mid" %.SND "audio/basic" %.TIF "image/tiff" %.TIFF "image/tiff" %.txt "text/plain" %.WAV "audio/wav" %.XML "text/xml" %.XSL "text/xml" ] Mime-Type: function [Filename [file!]] [Mime] [ all [ not found? Mime: select Mime-Types find Filename "." Mime: "application/x-msdownload" ] Mime ] Not-Found: func [Connection [port!] Web [file!] Filename [file!]] [ insert Connection rejoin [ "HTTP/1.0" " " "404 Not Found" newline "Content-type:" "text/html" newline newline HTML [ title "404 Not Found" body h1 "Error - 404 Not Found" "File not found!" ] ] ] Forbidden: func [Connection [port!]] [ insert Connection rejoin [ "HTTP/1.0" " " "400 Forbidden" newline "Content-type: " "text/html" newline newline HTML [ title "400 Forbidden" body h1 "Error - 400 Forbidden" "Forbidden!" ] ] ] Post: func [Connection [port!] Request [string!]] [ Serve Connection "text/html" reduce [ HTML [ title "Request" body h1 "Request" pre Request ] ] ] Get-Directory: function [Connection [port!] Web [file!] Directory [file!]] [Files] [ if error? try [ Files: read clean-path join Web Directory ][ Forbidden Connection exit ] Serve Connection "text/html" reduce [ HTML [ title join "Directory: " form Directory body h1 join "Directory: " form Directory list map sort Files func [Filename] [ a join Directory Filename form Filename ] ] ] ] Get-File: function [Connection [port!] Filename [file!]] [Data] [ either error? try [Data: read/binary Filename] [ Forbidden Connection ][ Serve Connection Mime-Type Filename Data ] ] Get: function [Connection [port!] Web [file!] Filename [file!]] [Absolute] [ Absolute: clean-path join Web Filename ifs/default [ not found? find Absolute Web [ Forbidden Connection ] not exists? Absolute [ Not-Found Connection Web Filename ] dir? Absolute [ Filename: join Absolute %index.htm if exists? Filename [ Get-File Connection Filename ] Filename: join Absolute %Index.html if exists? Filename [ Get-File Connection Filename ] Get-Directory Connection Web Filename ] ][ Get-File Connection Absolute ] ] Serve: func [Connection [port!] Mime [string!] Data] [ write-io Connection Data: append rejoin [ "HTTP/1.0" " " "200 OK" newline "Content-type: " Mime newline newline ] Data length? Data ] Stop: false set 'Webserver function [ "Serves Webpages." Port [integer!] Web [file!] /Print-Request ][ Listen Connection Request Filename ][ Listen: open/lines join tcp://: Port Stop: false while [not Stop] [ Connection: first wait Listen Request: make string! 1024 repend Request [first Connection newline] while [not 1 = length? Connection/state/inBuffer] [ repend Request [first Connection newline] ] if Print-Request [print Request] ifs/default [ parse Request [thru "POST " to end] [ Post Connection Request ] parse Request [thru "GET " copy Filename to " HTTP" to end] [ Filename: to-file replace/all Filename " " " " Get Connection Web Filename ] ][ Forbidden Connection ] close Connection ] close Listen ] ] ] -- Attached file included as plaintext by Listar -- -- File: Spider.r [ Rebol [ Name: 'Spider File: %Spider.r Title: "Spider" Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 25/October/2000 Purpose: "In place editing of web pages" Version: 1.1.0 History: [ 1.1.0 {Put in Print-Request refinement.} 1.0.0 "Original" ] ] secure allow do %../Webserver/Webserver.r print rejoin [ system/script/title ", version: " system/script/header/version "." newline {Press "Esc" key to stop.} ] Port: 7777 Sparrow: make object! [ Edit: HTML!/Fragment [ a %/Edit.rsp image %/Edit.gif 14x11 "Edit" ] Editing: HTML!/Fragment [ a %/Editing.rsp image %/Editing.gif 11x7 "Editing" ] Add: HTML!/Fragment [ a %/Add.rsp image %/Add.gif 9x8 "Add" ] Link: HTML!/Fragment [ a %/Link.rsp image %/Link.gif 12x10 "Link" ] ] Supercede: func [Object [object!] Block [block!]] [ do bind Block in Object 'self ] Supercede Webserver! [ Not-Found: function [Connection [port!] Web [file!] Filename [file!]] [Page] [ Page: HTML [ title join "[" [ Filename "]" ] body h1 [Sparrow/Edit join "[" [ Filename "]" ]] Sparrow/Add ] if error? try [ write clean-path join Web Filename Page Serve Connection "text/html" Page ][ Forbidden Connection ] ] ] browse join http://localhost: [Port "/" ] ; Webserver/Print-Request Port %/c/Rebol/Spider/Web ; Webserver/Print-Request Port %/c Webserver/Print-Request Port %"/c/PROJECTS/HTML/Secret Sorceress" ]