示例#1
0
  private int processHandshake(Packet p, InetAddress ip, int port) throws Exception {
    // System.out.println("Got handshake");
    // Get connection information
    this.numMessages = p.getNumMessages();
    this.totalDataSize = p.getTotalDataLength();
    this.seqNum = p.getSeqNum();

    // Respond
    // System.out.println("RT: Sending handshake response");
    Packet hsp = new Packet(seqNum);
    hsp.assembleHandshakePacket();
    packet = new DatagramPacket(hsp.getPacketData(), hsp.getPacketSize(), ip, port);
    socket.send(packet);

    // System.out.println("RT: Done with handshake:\n\tStarting seqnum: "+seqNum+"\n\tTotal datalen:
    // "+totalDataSize);
    return 1; // FIXME p.getNumMessages();
  }
示例#2
0
  private boolean sendAck(Packet p, DatagramPacket dp) {

    // Respond
    // System.out.println("RT: Sending ack for packet w/ seqnum: " + p.getSeqNum());
    Packet hsp = new Packet(p.getSeqNum());
    hsp.assembleHandshakePacket();
    packet =
        new DatagramPacket(hsp.getPacketData(), hsp.getPacketSize(), dp.getAddress(), dp.getPort());

    try {
      socket.send(packet);
    } catch (Exception e) {
      System.out.println("RT: Could not send ack packet:\n" + e.getMessage());
      return false;
    }

    return true;
  }