Socket Comm Sequence Issue

Björnke von Gierke bvg at mac.com
Fri Apr 15 15:03:27 EDT 2005


On Apr 15 2005, at 19:42, Ken Ray wrote:

> When do you trigger "sendData"? When I put this into two stacks and 
> open
> them, it puts them both into "accept" mode, but neither sends anything 
> to
> the other.
>
> What I'm trying to accomplish is that App 1 launches, it in turn 
> launches
> App 2, and both of them are in a two-way communication session...
>
> Any suggestions on scripting the critical "who talks first" step? 
> Because if
> someone talks before the other one is listening, you're hosed...

I suggest that the app that launches first is the one that makes the 
first call, that way it is simple to get communication going.
With modifying brians example you could try this approach, where you 
see how both stacks communicate, but only one stack starts the 
connection.
Note that you need to send an openStack to stack 2, and to start 
sending stuff send a sendData to stack 1 AFTER you did that.

for further question you might want to join the chatrev, i can help you 
faster there! (See signature)

--stack 1 script:

### open a new socket to be the sender of data
on sendData
   open socket to "127.0.0.1:9000" with message "socketOpen"
end sendData

### once the socket is open, send some data
on socketOpen s
   put "Writing to socket"&&s
   write ("Hello my name is"&&(the long name of this stack))&cr to 
socket s with message "dataSent"
end socketOpen

### once the data is sent, read for a reply
on dataSent s,d
   read from socket s for 1 line with message "gotReply"
end dataSent

### display the confirmation message
on gotReply s,d
   answer d
end gotReply


--stack 2 script:

### accept connections immediately
on openStack
   accept connections on port 8999 with message "gotConnect"
end openStack

### receive a new connection and begin reading data from it
on gotConnect s
   read from socket s for 1 line with message "gotData"
end gotConnect

### got the data, report it and send confirmation back
on gotData s,d
   answer "Application 1 says:"&&d
   write "OK"&cr to socket s
   close socket s
end gotData

-- 

official ChatRev page:
http://chatrev.cjb.net

Chat with other RunRev developers:
go stack URL "http://homepage.mac.com/bvg/chatrev1.3.rev"




More information about the use-livecode mailing list