Examples of DatagramPacket


Examples of io.netty.channel.socket.DatagramPacket

                remoteAddress = new InetSocketAddress(Inet4Address.getByName(address), port);
            } else {
                remoteAddress = new InetSocketAddress(Inet6Address.getByName(address), port);
            }

            DatagramPacket packet = new DatagramPacket(ReferenceCountUtil.retain(buf.slice(offset, length)), remoteAddress, localAddress);
            channelFuture.channel().writeAndFlush(packet);
        } catch (UnknownHostException e) {
            UDPWrap.this.process.getNodyn().handleThrowable(e);
            return e;
        }
View Full Code Here

Examples of java.net.DatagramPacket

        ackBuf[6] = 0;
        ackBuf[7] = 0;
        ackBuf[8] = 0;
        ackBuf[9] = 0;
      }
      socket.send(new DatagramPacket(ackBuf, ackBuf.length, addr));
    }
View Full Code Here

Examples of java.net.DatagramPacket

      buf[7] = (byte) (datagramStamp >>> 0);

      datagramStamp++;
      size++;
      if (serverInfo.handshaken) {
        socket.send(new DatagramPacket(buf, count, serverAddr));
      }
      count = 8;
    }
View Full Code Here

Examples of java.net.DatagramPacket

      int boot = getBootTS();
      handshakeBuf[0] = (byte) (boot >>> 24);
      handshakeBuf[1] = (byte) (boot >>> 16);
      handshakeBuf[2] = (byte) (boot >>> 8);
      handshakeBuf[3] = (byte) (boot >>> 0);
      socket.send(new DatagramPacket(handshakeBuf, handshakeBuf.length, addr));
    }
View Full Code Here

Examples of java.net.DatagramPacket

      for (InetAddress address : Collections.list(iface.getInetAddresses())) {
        if (!address.isSiteLocalAddress()) continue;
        // Java 1.5 doesn't support getting the subnet mask, so try the two most common.
        byte[] ip = address.getAddress();
        ip[3] = -1; // 255.255.255.0
        socket.send(new DatagramPacket(data, data.length, InetAddress.getByAddress(ip), udpPort));
        ip[2] = -1; // 255.255.0.0
        socket.send(new DatagramPacket(data, data.length, InetAddress.getByAddress(ip), udpPort));
      }
    }
    if (DEBUG) debug("kryonet", "Broadcasted host discovery on port: " + udpPort);
  }
View Full Code Here

Examples of java.net.DatagramPacket

    DatagramSocket socket = null;
    try {
      socket = new DatagramSocket();
      broadcast(udpPort, socket);
      socket.setSoTimeout(timeoutMillis);
      DatagramPacket packet = new DatagramPacket(new byte[0], 0);
      try {
        socket.receive(packet);
      } catch (SocketTimeoutException ex) {
        if (INFO) info("kryonet", "Host discovery timed out.");
        return null;
      }
      if (INFO) info("kryonet", "Discovered server: " + packet.getAddress());
      return packet.getAddress();
    } catch (IOException ex) {
      if (ERROR) error("kryonet", "Host discovery failed.", ex);
      return null;
    } finally {
      if (socket != null) socket.close();
View Full Code Here

Examples of java.net.DatagramPacket

    try {
      socket = new DatagramSocket();
      broadcast(udpPort, socket);
      socket.setSoTimeout(timeoutMillis);
      while (true) {
        DatagramPacket packet = new DatagramPacket(new byte[0], 0);
        try {
          socket.receive(packet);
        } catch (SocketTimeoutException ex) {
          if (INFO) info("kryonet", "Host discovery timed out.");
          return hosts;
        }
        if (INFO) info("kryonet", "Discovered server: " + packet.getAddress());
        hosts.add(packet.getAddress());
      }
    } catch (IOException ex) {
      if (ERROR) error("kryonet", "Host discovery failed.", ex);
      return hosts;
    } finally {
View Full Code Here

Examples of java.net.DatagramPacket

         }
         else
            log.fine("The progress listener is null");

         if (udp && this.sockUDP!=null && this.sock!=null) {
            DatagramPacket dp = new DatagramPacket(msg, msg.length, this.sock.getInetAddress(), this.sock.getPort());
            //DatagramPacket dp = new DatagramPacket(msg, msg.length, sock.getInetAddress(), 32001);
            this.sockUDP.send(dp);
            if (log.isLoggable(Level.FINE)) log.fine("UDP datagram is send");
         }
         else {
View Full Code Here

Examples of java.net.DatagramPacket

            }

            log.info("Started successfully " + getType() + " UDP driver on '" + socketUrl.getUrl() + "'");

            byte packetBuffer[] = new byte[MAX_PACKET_SIZE];
            DatagramPacket packet = new DatagramPacket(packetBuffer, packetBuffer.length);
            MsgInfo receiver = null;
            listenerReadyUDP = true;
            while (runningUDP) {
               try {
                  socketUDP.receive(packet);
               }
               catch (IOException e) {
                  if (e.toString().indexOf("closed") == -1) {
                     log.severe("Error receiving packet from '" + socketUrl.getUrl() + "' : " + e.toString());
                  }
                  else {
                     if (log.isLoggable(Level.FINE)) log.fine("UDP datagram socket shutdown '" + socketUrl.getUrl() + "' : " + e.toString());
                  }
                  return;
               }
               if (log.isLoggable(Level.FINE))
                  log.fine("UDP packet arrived, size=" + packet.getLength() + " bytes");
               if (!runningUDP) {
                  log.info("Closing server '" + socketUrl.getUrl() + "'");
                  return;
               }
               int actualSize = packet.getLength();
               if (packet.getLength() > MAX_PACKET_SIZE) {
                  log.warning("Packet has been truncated, size=" + packet.getLength() + ", MAX_PACKET_SIZE=" + MAX_PACKET_SIZE);
                  actualSize = MAX_PACKET_SIZE;
               }
               InputStream iStream = new ByteArrayInputStream(packet.getData(), 0, actualSize);
               try {
                  receiver = MsgInfo.parse(glob, null, iStream, null/*getMsgInfoParserClassName()*/, getPluginConfig())[0];
               }
               catch (Throwable e) {
                  log.severe("Error parsing data from UDP packet: " + e);
View Full Code Here

Examples of java.net.DatagramPacket

        } catch( UnknownHostException uhe ) {
        }

        snd_buf = new byte[SND_BUF_SIZE];
        rcv_buf = new byte[RCV_BUF_SIZE];
        out = new DatagramPacket( snd_buf, SND_BUF_SIZE, baddr, NAME_SERVICE_UDP_PORT );
        in  = new DatagramPacket( rcv_buf, RCV_BUF_SIZE );

        if( RO == null || RO.length() == 0 ) {

            /* No resolveOrder has been specified, use the
             * default which is LMHOSTS,WINS,BCAST,DNS or just
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.