Examples of UDPPacketBuffer


Examples of com.ngt.jopenmetaverse.shared.sim.buffers.UDPPacketBuffer

      public void run()
      {
        //While it is not shutdown
        while (!shutdownFlag)
        {
          final UDPPacketBuffer buf = new UDPPacketBuffer();
          DatagramPacket receivePacket = new DatagramPacket(buf.getData(), buf.getData().length);
          try {
            udpSocket.receive(receivePacket);
            buf.setDataLength(receivePacket.getLength());
            buf.setRemoteEndPoint(receivePacket.getSocketAddress());
            //Start another receiving, it will keep the server going

            //start another thread to process the packet
            threadPool.execute(new Runnable(){
              public void run()
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.sim.buffers.UDPPacketBuffer

      if (sendCloseCircuit)
      {
        // Try to send the CloseCircuit notice
        CloseCircuitPacket close = new CloseCircuitPacket();

        UDPPacketBuffer buf = new UDPPacketBuffer(remoteEndPoint);
        byte[] data = close.ToBytes();
        Utils.arraycopy(data, 0, buf.getData(), 0, data.length);
        buf.setDataLength(data.length);

        AsyncBeginSend(buf);
      }

      // Shut the socket communication down
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.sim.buffers.UDPPacketBuffer

    }
  }

  public void SendPacketData(byte[] data, int dataLength, PacketType type, boolean doZerocode)
  {
    UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndPoint, Packet.MTU);

    // Zerocode if needed
    if (doZerocode)
    {
      try { dataLength = Helpers.ZeroEncode(data, dataLength, buffer.getData()); }
      catch (IndexOutOfBoundsException e)
      {
        // The packet grew larger than Packet.MTU bytes while zerocoding.
        // Remove the MSG_ZEROCODED flag and send the unencoded data
        // instead
        data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
        Utils.arraycopy(data, 0, buffer.getData(), 0, dataLength);
      }
    }
    else
    {
      Utils.arraycopy(data, 0, buffer.getData(), 0, dataLength);
    }
    buffer.setDataLength(dataLength);

    //region Queue or Send

    NetworkManager.OutgoingPacket outgoingPacket = new NetworkManager.OutgoingPacket(this, buffer, type);
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.sim.buffers.UDPPacketBuffer

    //endregion
  }

  protected void SendPacketFinal(NetworkManager.OutgoingPacket outgoingPacket)
  {
    UDPPacketBuffer buffer = outgoingPacket.Buffer;
    byte flags = buffer.getData()[0];
    boolean isResend = (flags & Helpers.MSG_RESENT) != 0;
    boolean isReliable = (flags & Helpers.MSG_RELIABLE) != 0;

    // Keep track of when this packet was sent out (right now)
    outgoingPacket.TickCount = Utils.getUnixTime();

    //region ACK Appending

    int dataLength = buffer.getDataLength();

    // Keep appending ACKs until there is no room left in the packet or there are
    // no more ACKs to append
    //uint
    long ackCount = 0;
    //uint
    Long ack;
    while (dataLength + 5 < Packet.MTU && ((ack = PendingAcks.poll())!=null))
    {
      Utils.uintToBytes(ack, buffer.getData(), dataLength);
      dataLength += 4;
      ++ackCount;
    }

    if (ackCount > 0)
    {
      // Set the last byte of the packet equal to the number of appended ACKs
      buffer.getData()[dataLength++] = (byte)ackCount;
      // Set the appended ACKs flag on this packet
      buffer.getData()[0] |= Helpers.MSG_APPENDED_ACKS;
    }

    buffer.setDataLength(dataLength);

    //endregion ACK Appending

    if (!isResend)
    {
      // Not a resend, assign a new sequence number
      //uint
      long sequenceNumber = Sequence.incrementAndGet();
      Utils.uintToBytes(sequenceNumber, buffer.getData(), 1);
      outgoingPacket.SequenceNumber = sequenceNumber;

      if (isReliable)
      {
        // Add this packet to the list of ACK responses we are waiting on from the server
View Full Code Here

Examples of com.ngt.jopenmetaverse.shared.sim.buffers.UDPPacketBuffer


  private void sendAndReceiveData(UDPBase udp, InetSocketAddress saddress,
      UDPPacketBuffer[] bufArray, byte[] data, int length)
  {
    UDPPacketBuffer buf = new UDPPacketBuffer(saddress, length);
    Utils.arraycopy(data, 0, buf.getData(), 0, length);
    buf.setDataLength(length);
    JLogger.debug("Sending data to UDP server");
    bufArray[0] = buf;
    udp.AsyncBeginSend(buf)
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.