idiotic newibe needs help (controlling two sockets)
[1/4] from: lmecir:mbox:vol:cz at: 7-Nov-2001 20:37
Hi pm,
<<
...
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
]
]
>>
This is an idea how to merge the
scripts. Warning, untested!
REBOL []
readbuffer: make string! 1000
listenport: open tcp://:4321
do http://www.reboltech.com/library/scripts/telnet.r
ports: [listenport]
telnets: []
forever [
; anything new?
wait ports
; a new connection?
if wait [0 listenport] [
; add new client connection
append ports first listenport
; for a new client open a new telnet port
; this is only a sample,
; you must change it to whatever is appropriate
telnet: open telnet://fla007:[hsd24107--cyberspace--org]
append telnets telnet
append ports telnet/sub-port
print "New connection"
]
connections: next ports
while [(length? connections) >= 2] [
set [client-port telnet-sub] connections
if wait [0 telnet-sub] [
read-io telnet-sub readbuffer 1000
insert client-port readbuffer
clear readbuffer
]
if wait [0 client-port] [
len: read-io client-port readbuffer 1000
either len = 0 [
telnet: pick telnets i: (index? connections) / 2
close telnet
remove at telnets i
close client-port
remove/part connections 2
] [
insert telnet readbuffer
connections: skip connections 2
clear readbuffer
]
]
]
]
Cheers
Ladislav
[2/4] 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
]
]
[3/4] from: greggirwin:mindspring at: 7-Nov-2001 0:01
I won't be much help to you, but maybe Graham's GoRim stuff would give you
some clues.
--Gregg
[4/4] from: flashcgi::yahoo at: 6-Nov-2001 23:24
well i looked at this and didnt understand it...haha..im too much of a
newbie ;)
p