multiple local sockets
Nicolas Cueto
nrkweto03 at hotmail.com
Thu Dec 30 19:42:23 EST 2004
Hello All,
Spent a long day yesterday! Both figuring out a "solution" to a
multiple-ports problem, and realizing finally that my understanding of Rev's
implementation of sockets is seriously flawed. Specifically, the problem
this time seems to be my unclear understanding of how Rev identifies sockets
to and from a single port.
I was hoping someone might care to comment on the following before-and-after
script outlines, perhaps even going so far as to also suggest a simpler way.
Appended below, too, is the perhaps relevant sections from the Rev
documentation, but the implementation of which I'm afraid I could not
understand (i.e., how or where to actually refer in a script to a
non-numeric socket identifier I've arbitrarily assigned).
As always, thank you... and a Happy Year of The Chicken!
Cheers,
Nicolas Cueto
--------------------------------------
######THE "BEFORE" SCRIPT##########
local tRawData
on openCard
accept connections on port 8080 with message "netConnect"
open socket to "192.168.1.11:8025" with message "sendItOne"
open socket to "192.168.1.11:8025" with message "sendItTwo"
end openCard
on netConnect incomingMessage
read from socket incoming message until [arbitrary end marker]
put it into receivedData
close socket incomingMessage
if "[request 1]" is in receivedData then
put receivedData into tRawData
processRawData
end if
if "[request 2]" is in receivedData then
put receivedData into tRawData
processRawData
end netConnect
on processRawData
if "[request 1]" is in tRawData then do stuff on local stack
if "[request 2]" is in tRawData then do other stuff on local stack
end processRawData
on sendItOne sOne
put "[request1]" into tData
write tData to socket sOne
close socket sOne
end sendItOne
on sendItTwo sTwo
put "[request2]" into tData
write tData to socket sTwo
close socket sTwo
end sendItOne
########## THE "AFTER" SCRIPT############
local tRawDataOne, tRawDataTwo
on openCard
accept connections on port 8080 with message "netConnectOne"
accept connections on port 8081with message "netConnectOne"
open socket to "192.168.1.11:8025" with message "sendItOne"
open socket to "192.168.1.11:8026" with message "sendItTwo"
end openCard
on netConnectOne incomingMessageOne
read from socket incoming messageOne until [arbitrary end marker]
put it into receivedData
close socket incomingMessageOne
if "[request 1]" is in receivedData then
put receivedData into tRawDataOne
processRawDataOne
end netConnectOne
on netConnectTwo incomingMessageTwo
read from socket incoming messageTwo until [arbitrary end marker]
put it into receivedData
close socket incomingMessageTwo
if "[request 1]" is in receivedData then
put receivedData into tRawDataTwo
processRawDataTwo
end netConnectOne
on processRawDataOne
do stuff on local stack
end processRawDataOne
on processRawDataTwo
do other stuff on local stack
end processRawDataTwo
on sendItOne sOne
put "[request1]" into tData
write tData to socket sOne
close socket sOne
end sendItOne
on sendItTwo sTwo
put "[request2]" into tData
write tData to socket sTwo
close socket sTwo
end sendItOne
#########REV DOC: accept command###########
When a connection is made or a datagram is received, the accept command
creates a new socket that can be used to communicate with the other system
(or process). When using the close socket, read from socket, or write to
socket commands, you can refer to this socket with a socket identifier that
looks like this:
host:port[|connectionID]
where the connectionID is a number assigned by the accept command. (You only
need to specify the connection number if there is more than one socket
connected to a particular port and host.)
#########REV DOC:open socket command#######
Note: When the accept command creates a socket, it assigns a number as the
connection name. If you are using both the open socket command and the
accept command to connect to the same port on the same host, make sure to
use a non-numeric connection name that won?t conflict with the numbers
assigned by the accept command. This ensures that you can always refer to
two different sockets by distinct socket identifiers.
More information about the use-livecode
mailing list