Exemplo n.º 1
0
  /**
   * Initiate connection to a remote socket
   *
   * @param destAddr int Destination node address
   * @param destPort int Destination port
   * @return int 0 on success, -1 otherwise
   */
  public int connect(int destAddr, int destPort) {
    // if not starting from a closed state, connect should fail.
    if (!isClosed() || !isSender()) {
      pe(this, " connect() called on inappropriated");
      return -1;
    }

    p(this, 3, "Connect() to:  " + destAddr + ":" + destPort);
    this.tsid.remoteAddr = destAddr;
    this.tsid.remotePort = destPort;

    tcpMan.add(this.tsid, this);
    tcpMan.sendSYN(this.tsid);
    this.state = State.SYN_SENT;

    return 0;
  }