Class TCPIPLink

java.lang.Object
org.jcsp.net.Link
org.jcsp.net.tcpip.TCPIPLink
All Implemented Interfaces:
CSProcess

class TCPIPLink extends Link
Implements a link running over TCP/IP sockets. See the definition of Link for full details.
See Also:
  • Field Details

  • 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:
      runTxRxLoop in class Link
    • waitForReplies

      protected void waitForReplies(int numRepliesOutstanding)
      Waits for numRepliesOutstanding instances of LinkLost to arrive from the txChannel.
      Overrides:
      waitForReplies in class Link
      Parameters:
      numRepliesOutstanding - LinkLost instances 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).
      Overrides:
      connect in class Link
      Returns:
      true on success, false on failure.
    • createResources

      protected boolean createResources()
      Create the object streams used to communicate with the peer system. Called internally by the superclass.
      Overrides:
      createResources in class Link
      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 this NodeID and a process to receive the peer node ID. Called internally by the superclass.
      Overrides:
      exchangeNodeIDs in class Link
      Returns:
      true on success, false on failure
    • writeTestObject

      protected void writeTestObject(Object obj) throws Exception
      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 the readTestObject method at the peer node.
      Overrides:
      writeTestObject in class Link
      Parameters:
      obj - Object to be sent
      Throws:
      Exception
    • readTestObject

      protected Object readTestObject() throws Exception
      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 to writeTestObject at the peer node.
      Overrides:
      readTestObject in class Link
      Returns:
      the object received.
      Throws:
      Exception
    • writeLinkDecision

      protected void writeLinkDecision(boolean use) throws Exception
      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 the readLinkDecision method at the peer node.
      Overrides:
      writeLinkDecision in class Link
      Parameters:
      use - boolean decision value to send.
      Throws:
      Exception
    • readLinkDecision

      protected boolean readLinkDecision() throws Exception
      Reads a boolean link decision from the input stream. Called internally during the handshaking sequence by the superclass. Returns the parameter passed to writeLinkDecision at the peer node.
      Overrides:
      readLinkDecision in class Link
      Returns:
      the boolean decision.
      Throws:
      Exception
    • destroyResources

      protected void destroyResources()
      Closes the streams and the socket, if needed. Surpresses errors.
      Overrides:
      destroyResources in class Link
    • 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.