Package org.jcsp.net.tcpip
Class TCPIPLink
java.lang.Object
org.jcsp.net.Link
org.jcsp.net.tcpip.TCPIPLink
- All Implemented Interfaces:
CSProcess
Implements a link running over TCP/IP sockets. See the definition of
Link for
full details.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classThe process which creates rxStream.private classThe process which creates txStream.private classThe process which recieves the remote Id.private classThe process which recieves from a socket.private classThe process which sends our Id.private classThe process which does transmission to a socket.private classAn object of this type is used by RxLoop to poison TxLoop. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intSize of Java buffers.private static StringHandshaking string.private TCPIPAddressIDThe other computer's IP address and port.private ObjectInputStreamThe stream for reading from the socket.private SocketThe actual socket.private ObjectOutputStreamThe stream for reading from the socket.Fields inherited from class org.jcsp.net.Link
remoteNodeID, sendNodeID, txChannel -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcloseRx()Closes the Rx stream and the socket, if needed.private voidCloses the socket, if needed.private voidcloseTx()Closes the Tx stream and the socket, if needed.protected booleanconnect()Connect to remote host.protected booleanCreate the object streams used to communicate with the peer system.protected voidCloses the streams and the socket, if needed.protected booleanPerforms the node exchange part of the handshaking process.protected booleanReads a boolean link decision from the input stream.protected ObjectReads a test object from the input stream.protected voidRun the send and receive threads to marshall and unmarshall objects.protected voidstart(boolean newProcess) Start this Link but allow the caller to continue in parallel.protected voidwaitForReplies(int numRepliesOutstanding) Waits fornumRepliesOutstandinginstances ofLinkLostto arrive from thetxChannel.protected voidwriteLinkDecision(boolean use) Writes a boolean link decision value to the output stream.protected voidwriteTestObject(Object obj) Writes a test object to the output stream, flushing and resetting the stream afterwards.Methods inherited from class org.jcsp.net.Link
deliverReceivedObject, equals, getPingTime, getProtocolID, getReadSequence, getRemoteNodeID, getTxChannel, hashCode, obtainNodeID, performedPingTest, ping, run
-
Field Details
-
remoteTCPIPAddress
The other computer's IP address and port. -
socket
The actual socket. -
rxStream
The stream for reading from the socket. -
txStream
The stream for reading from the socket. -
PROTOCOL_IDENTIFIER
Handshaking string. -
BUFFER_SIZE
private static final int BUFFER_SIZESize of Java buffers. Note that there are also OS buffers, set usingSocket.setReceiveBufferSize(int)andSocket.setSendBufferSize(int).- See Also:
-
-
Constructor Details
-
TCPIPLink
TCPIPLink(Socket socket) Constructor for using an existing socket.- Parameters:
socket- The socket to the remote computer, which must already be open and active. You must not have transmitted anything over the socket.
-
TCPIPLink
TCPIPLink(Socket socket, boolean client) Constructor for using an existing socket.- Parameters:
socket- The socket to the remote computer, which must already be open and active. You must not have transmitted anything over the socket.client- Tells the link whether to act as a client or a server during the handshake process
-
TCPIPLink
TCPIPLink(TCPIPAddressID remoteTCPIPAddress) Constructor for connecting to a remote computer. The actual connect happens when you run the process using start().- Parameters:
remoteTCPIPAddress- The remote computer to connect to.
-
-
Method Details
-
runTxRxLoop
protected void runTxRxLoop()Run the send and receive threads to marshall and unmarshall objects.- Overrides:
runTxRxLoopin classLink
-
waitForReplies
protected void waitForReplies(int numRepliesOutstanding) Waits fornumRepliesOutstandinginstances ofLinkLostto arrive from thetxChannel.- Overrides:
waitForRepliesin classLink- Parameters:
numRepliesOutstanding-LinkLostinstances to wait for.
-
start
protected void start(boolean newProcess) Start this Link but allow the caller to continue in parallel. This is the similar to "new ProcessManager(this).start()" - except that Link no longer implements CSProcess, so you can't do that. -
connect
protected boolean connect()Connect to remote host. Should only be called for client-side Links which have not yet been connected. (i.e. where socket==null and remoteAddress != null). -
createResources
protected boolean createResources()Create the object streams used to communicate with the peer system. Called internally by the superclass.- Overrides:
createResourcesin classLink- Returns:
- true on success, false on failure
-
exchangeNodeIDs
protected boolean exchangeNodeIDs()Performs the node exchange part of the handshaking process. Creates a process to send thisNodeIDand a process to receive the peer node ID. Called internally by the superclass.- Overrides:
exchangeNodeIDsin classLink- Returns:
- true on success, false on failure
-
writeTestObject
Writes a test object to the output stream, flushing and resetting the stream afterwards. Called internally by the superclass during the testing stage to determine link speed. The parameter passed to this method must be returned by thereadTestObjectmethod at the peer node.- Overrides:
writeTestObjectin classLink- Parameters:
obj- Object to be sent- Throws:
Exception
-
readTestObject
Reads a test object from the input stream. Called internally by the superclass during the testing stage to determine link speed. Returns the parameter passed towriteTestObjectat the peer node.- Overrides:
readTestObjectin classLink- Returns:
- the object received.
- Throws:
Exception
-
writeLinkDecision
Writes a boolean link decision value to the output stream. Called internally by the superclass during the handshaking sequence. The parameter passed to this method must be returned by thereadLinkDecisionmethod at the peer node.- Overrides:
writeLinkDecisionin classLink- Parameters:
use- boolean decision value to send.- Throws:
Exception
-
readLinkDecision
Reads a boolean link decision from the input stream. Called internally during the handshaking sequence by the superclass. Returns the parameter passed towriteLinkDecisionat the peer node.- Overrides:
readLinkDecisionin classLink- Returns:
- the boolean decision.
- Throws:
Exception
-
destroyResources
protected void destroyResources()Closes the streams and the socket, if needed. Surpresses errors.- Overrides:
destroyResourcesin classLink
-
closeRx
private void closeRx()Closes the Rx stream and the socket, if needed. Surpresses errors. -
closeTx
private void closeTx()Closes the Tx stream and the socket, if needed. Surpresses errors. -
closeSocket
private void closeSocket()Closes the socket, if needed. Surpresses errors.
-