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

Creating a Server Port Cookbook example - newbie question

 [1/2] from: dgarrard::nufocusinc::com at: 13-Oct-2003 19:08


One of the examples in the "Cookbook", authored by Paul Tretter is "Creating a Server Port" http://www.rebol.net/cookbook/recipes/0034.html Server Code: listen: open tcp://:12345 waitports: [listen] forever [ data: wait waitports either same? data listen [ active-port: first listen append waitports active-port ][ incoming-from-remote: first data print incoming-from-remote ] ] I have set this up and it works as expected if I manually type into a remote console the data insertion calls he suggests: from-remote: open tcp://localhost:12345 insert from-remote "test" test arrives at the server... But if I create the following script: REBOL [ Title: "Open a Server Port - Now connect with Client 1" Date: 11-Oct-2003 ] from-remote: open tcp://localhost:12345 insert from-remote "test" quit it crashes the "server" if I run it by simply double-clicking. Server reports: ** Script Error: Out of range or past end ** Where: forever ** Near: incoming-from-remote: first data comment [print incoming-from-remote]
>>
How do I gracefully exit out of my client script without crashing the server. Or does the server need more complete error handling? Thanks in advance... D Garrard

 [2/2] from: g:santilli:tiscalinet:it at: 14-Oct-2003 10:29


Hi David, On Tuesday, October 14, 2003, 1:08:01 AM, you wrote: DG> listen: open tcp://:12345 DG> waitports: [listen] DG> forever [ DG> data: wait waitports DG> either same? data listen [ DG> active-port: first listen DG> append waitports active-port DG> ][ DG> incoming-from-remote: first data DG> print incoming-from-remote DG> ] DG> ] I'd do it as: listen: open/no-wait tcp://:12345 waitports: [listen] forever [ port: wait waitports either same? port listen [ active-port: first listen append waitports active-port ] [ incoming-from-remote: copy port either incoming-from-remote [ prin incoming-from-remote ] [ remove find waitports port close port ] ] ] (Well, actually I'd do it event-based, but maybe this way it is more appropriate for a cookbook.) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/