This node provides a network manager and transceiver object that can be used to access data over a network using StreamPeerTCP. The transceiver does asynchornous operations and provides appropriate signals for the various network activity events.
One caveat is in the StreamPeerTCP.connect() call. If the endpoint is anything other than available this method will permablock and not even return an error when it could (such as connection refused when no application listens at the specified port). I work around this be wrapping the .connect() in thread and then time the thread. If it times out the thread should be killed. There's no way to kill the thread so you wind up with the debugger complaining about the thread still active when the reference is destroyed (so obviously that doesn't kill the thread). I have another question posted asking about how to kill a stuck thread which has yet to receive any answer (How to Kill a Permablocked Thread).
Mostly works, except for not being able to kill the thread with a blocked .connect()
Anyways here's the class (inherits node):
# Network stream management
# Allows asynchronous network access with signals to indicate
# completion of accesses.
# The process loop will consume network data as it is received
# and place it into a recieving FIFO. Data bound for the network
# (the send_xxx methods) will placed into a sending FIFO. Bytes
# will come off the send FIFO as the underlying OS FIFO takes
# it up (put_data_partial).
# An additional signal is present and will fire if the connection
# is dropped.
# deletes amt bytes from beginning of rawarray
# nothing to do
# *** THIS IS A HACK ***
# We need a subarray (slice) operation to do this properly
# This hack will copy the entire data three times!!! O(N)
# as RawArray's copy when modified.
# Alas this hack is still faster than scriptlooping to
# left-delete using .remove() and having the data copied on
# each pass through the loop! O(N^2+N) (for a mere 10 KB
# of data scriptlooping results in 50 MB!!! of wasted copying,
# whereas this hack only copies 30K)
# this means the thread connected
# API gives no way to kill a thread???
# best we cand do then is force its refcount to 0
# indicate the timeout downstream
if (_st==0 or !host.is_connected()) and wasConnected:
if st==1 or st==2: