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

[REBOL] idiotic newibe needs help (controlling two sockets)

From: flashcgi:yah:oo at: 6-Nov-2001 17:19

hi just got to playing with rebol (from reading a slashdot article recently) and im amazed how easy it is to do stuff...please bear with me if my questions are too basic for this group okay, what i want to do is use rebol to create a socket server that a client can connect to, and from there have the server connect to a telnet server. the server then pipes back whatever the telnet server is giving and pipes forward whatever the connected client has. (my client NOT be in rebol but in flash) i have succesffully had my client connect to a simple socket server in rebol. (thanks to the great code on this list and the website, i have had success in connecting my client to the server. however, most code is see relies on a forever/while loop ... so how do i implmeent a sub-forever loop (for the connection to the telnet server). i guess this is multi-threading? (again forgive my ignorance, as im new to this kind of programming) incidently i have looked into rugby but havent found out how to integrate a non rebol client to it as it assumes it can use functions from the rugby.r file. anyhow, here are the two scripts im trying to merge together ========================================= multisession client by some other dude whose credits i cut off to make printing fit on one page REBOL [ Title: "Multiple session server" ] { This program demonstrates code that will handle multiple simultaneous TCP sessions using REBOL. You can try this program out by running it, then connecting to the telnet port. All data sent will be echoed on all other connections. } { readbuffer = buffer for reading in data listenport = listening on telnet port waitobjs = port objects to wait for events on } readbuffer: make string! 10000 listenport: open tcp://:4321 waitobjs: [ listenport ] { echoall = function to send data on all connections in connlist } echoall: make function! [ string ] [ foreach connection connlist [ insert connection string ] ;<--- here i want to send the telnet output to the client ] forever [ wait waitobjs { Did we have any new connections? } if not ( none? (wait [ 0 listenport]) ) [ append waitobjs first listenport print "New connection" ] connlist: next waitobjs connports: next waitobjs while [ ( length? connports ) > 0 ] [ conn: first connports either query conn [ {query: return true as lon gas we have a connection} if not ( none? (wait [0 conn]) ) [ len: read-io conn readbuffer 1000 either ( len == 0 ) [ { No data = connection closed } close conn remove connports print "Connection closed" ][ { Received data! } print readbuffer echoall readbuffer clear conn readbuffer: tail readbuffer ] ] connports: next connports ][ { this happens when a client closes the connection} close conn remove connports print "Connection closed" ] ] ] =========================================== TELNET CLIENT BY FRANK REBOL [ Title: "Demo client with telnet-protocol" Date: 6-Jul-2001 Version: 1.0.0 File: %telnet-client.r Author: "Frank Sievertsen" Purpose: "A simple telnet-client" Email: [fsievert--uos--de] Category: [3 tcp tutor net] ] do http://www.reboltech.com/library/scripts/telnet.r host: ask "Hostname:" ;host: join "[fla007--hsd24107]" "cyperspace.org" ;telnet: open join telnet:// host telnet: open telnet://fla007:[hsd24107--cyberspace--org] system/console/break: no forever [ port: wait [telnet/sub-port system/ports/input] either port = telnet/sub-port [ if none? str: copy telnet [break] ; write/append %log.txt str ; <=== this is where i want to redirect to the other server insert system/ports/output str ] [ insert telnet copy/part system/ports/input 1 ] ]