Hi-
I posted a response to this previously but it appears to have been lost. I'll try to reconstruct it from memory.
First, unfortunately there is no way to pass a value between script blocks. You can share scripts between script blocks but the values of the variables are scoped to the block itself.
There is a way to pass values between invocations of a script block however. This is the purpose of the 'state' variable. This variable is made available to your script each time your script block is invoked and its value is preserved across invocations of your script block.
As Python variables are essentially 'untyped' you can set this variable to any value you care to preserve. By default it is an integer with the value of zero. It could however be set to a dictionary or a list if you need to preserve multiple values.
There are several ways to address the type of problem you describe in your original post. The most obvious is to save your socket object to the state variable and then to check to see if it's a valid socket object at the top of your script. Such a script would look something like this:
import socket
#create socket if the state variable has not already been initialized as a socket
if not isinstance(state, socket):
state = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
state.connect(address, port);
# it is safe to work with your socket now
state.send('Hello World');
Another option would be to create a custom class which has the socket as one of its member variables. An instance of this class could then be saved to the state variable in the same fashion as demonstrated above. This would be more convenient in the case where you had additional variables you wanted keep associated with your socket.
I hope this helps. Let us know if you have more questions.
Thanks-
Frank