Class TCPIPLink
java.lang.Object
org.jcsp.net2.Link
org.jcsp.net2.tcpip.TCPIPLink
- All Implemented Interfaces:
CSProcess
A concrete implementation of a Link that operates over a TCP/IP based socket connection. For information on Link, see
the relative documentation.
It is perfectly possible for a user to create a TCPIPLink without going through the standard LinkFactory approach, although this is not recommended. For example:
TCPIPLink link = new TCPIPLink(address);
link.connect();
link.registerLink();
new ProcessManager(link).start();
Can be achieved using the LinkFactory:
link = LinkFactory.getLink(address);
The LinkFactory will create and start the Link automatically if required.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intDefines the size of the buffer to place on the incoming and outgoing streams.static booleanFlag to determine whether the Nagle algorithm should be activated.private TCPIPNodeAddressThe address of the remote Node.private SocketThe socket connected to the remote Node. -
Constructor Summary
ConstructorsConstructorDescriptionCreates new TCPIPLink from a Socket.TCPIPLink(TCPIPNodeAddress address) Creates a new TCPIPLink -
Method Summary
Modifier and TypeMethodDescriptionbooleanconnect()Connects the Link to the remote Node.protected booleanCreates any required resources.protected voidDestroys any resources used by the LinkGets the NodeAddress of the Node that this Link is connected toMethods inherited from class Link
getRemoteNodeID, getTxChannel, lostLink, registerLink, run
-
Field Details
-
BUFFER_SIZE
public static int BUFFER_SIZEDefines the size of the buffer to place on the incoming and outgoing streams. This is a rather large size, and for certain implementations, this may be reduced. It is unlikely that any sent object will be this large. -
NAGLE
public static boolean NAGLEFlag to determine whether the Nagle algorithm should be activated. Default is false (off). -
sock
The socket connected to the remote Node. -
remoteAddress
The address of the remote Node.
-
-
Constructor Details
-
TCPIPLink
Creates a new TCPIPLink- Parameters:
address- The address of the remote Node to connect to- Throws:
JCSPNetworkException- Thrown if something goes wrong during the creation process
-
TCPIPLink
TCPIPLink(Socket socket, NodeID nodeID) throws JCSPNetworkException Creates new TCPIPLink from a Socket. This is used internally by JCSP- Parameters:
socket- The socket to create the TCPIPLink withnodeID- The NodeID of the remote Node- Throws:
JCSPNetworkException- Thrown if there is a problem during the connection
-
-
Method Details
-
connect
Connects the Link to the remote Node. Exchanges the NodeIDs- Specified by:
connectin classLink- Returns:
- True if the Link successfully connected to the remote Link
- Throws:
JCSPNetworkException- Thrown if something goes wrong during the connection
-
createResources
Creates any required resources. For TCP/IP there is none.- Specified by:
createResourcesin classLink- Returns:
- True if all resources were created OK. Always the case in TCP/IP
- Throws:
JCSPNetworkException- Thrown if anything goes wrong during the creation process.
-
destroyResources
protected void destroyResources()Destroys any resources used by the Link- Specified by:
destroyResourcesin classLink
-
getRemoteAddress
Gets the NodeAddress of the Node that this Link is connected to- Returns:
- The NodeAddress of the remotely connected Node
-