Package java.net

Examples of java.net.DatagramPacket


        }

        // receive and send back some message
        for (int i = 0; i < CLIENT_COUNT; i++) {
            byte[] receiveData = new byte[1024];
            DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            serverSocket.receive(receivePacket);

            String sentence = new String(receivePacket.getData());
            LOG.info("RECEIVED  :" + sentence);

            InetAddress IPAddress = receivePacket.getAddress();
            int clientPort = receivePacket.getPort();
            DatagramPacket sendPacket = new DatagramPacket("tata".getBytes(), "tata".getBytes().length, IPAddress,
                    clientPort);
            serverSocket.send(sendPacket);
        }

        // does response was wrote and sent ?
View Full Code Here


    public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
        InetAddress serverAddress = InetAddress.getLocalHost();
        byte[] buffer = new byte[65507];
        sender = new DatagramSocket(port + 1);

        DatagramPacket pduSent = new DatagramPacket(data, data.length, serverAddress, port);
        DatagramPacket pduReceived = new DatagramPacket(buffer, data.length);
        sender.send(pduSent);

        boolean done = false;

        while (!done) {
            try {
                sender.receive(pduReceived);

                for (int i = 0; i < pduReceived.getLength(); ++i) {
                    counter.countDown();

                    if (counter.getCount() > 0) {
                        sender.send(pduSent);
                        break;
View Full Code Here

      }
      appender.close();
      String[] retval = new String[packets];
      byte[] buf = new byte[1000];
      for(int i = 0; i < packets; i++) {
          DatagramPacket p = new DatagramPacket(buf, 0, buf.length);
          ds.receive(p);
          retval[i] = new String(p.getData(), 0, p.getLength());
      }
      ds.close();
      return retval;
    }
View Full Code Here

      l.info("Hello, World");
      appender.close();
      String[] s = new String[3];
      byte[] buf = new byte[1000];
      for(int i = 0; i < 3; i++) {
          DatagramPacket p = new DatagramPacket(buf, 0, buf.length);
          ds.receive(p);
          s[i] = new String(p.getData(), 0, p.getLength());
      }
      ds.close();
      assertEquals("<14><!DOCTYPE", s[0].substring(0,13));
      assertEquals("<14></table>", s[2].substring(0,12));
    }
View Full Code Here

      l.info(msg);
      appender.close();
      String[] s = new String[8];
      byte[] buf = new byte[1200];
      for(int i = 0; i < 8; i++) {
          DatagramPacket p = new DatagramPacket(buf, 0, buf.length);
          ds.receive(p);
          assertTrue(p.getLength() <= 1024);
          s[i] = new String(p.getData(), 0, p.getLength());
      }
      ds.close();
      StringBuffer rcvbuf = new StringBuffer(s[0]);
      rcvbuf.delete(0, 4);
      for(int i = 1; i < 8; i++) {
View Full Code Here

                    s.setBroadcast(true);
                    s.joinGroup(address);
                    s.setReceiveBufferSize(64 * 1024);
                    s.setSoTimeout(5000);
                    byte[] bytes = new byte[64 * 1024];
                    DatagramPacket p = new DatagramPacket(bytes, bytes.length, address, Integer.parseInt(PORT));
                    s.receive(p);
                    SocketAddress sa = p.getSocketAddress();
                    String incoming = new String(p.getData(), 0, p.getLength(), "UTF-8");
                    int idx = incoming.indexOf("MessageID");
                    idx = incoming.indexOf('>', idx);
                    incoming = incoming.substring(idx + 1);
                    idx = incoming.indexOf("</");
                    incoming = incoming.substring(0, idx);
                    for (int x = 1; x < 4; x++) {
                        InputStream ins = WSDiscoveryClientTest.class.getResourceAsStream("msg" + x + ".xml");
                        String msg = IOUtils.readStringFromStream(ins);
                        msg = msg.replace("urn:uuid:883d0d53-92aa-4066-9b6f-9eadb1832366",
                                          incoming);
                        byte out[] = msg.getBytes("UTF-8");
                        DatagramPacket outp = new DatagramPacket(out, 0, out.length, sa);
                        s.send(outp);
                    }
                   
                    s.close();
                } catch (Throwable t) {
View Full Code Here

  private void runKeepFieldsTest(String keepFields) throws IOException {
    init(keepFields);
    source.start();
    // Write some message to the syslog port
    DatagramSocket syslogSocket;
    DatagramPacket datagramPacket;
    datagramPacket = new DatagramPacket(bodyWithTandH.getBytes(),
      bodyWithTandH.getBytes().length,
      InetAddress.getLocalHost(), source.getSourcePort());
    for (int i = 0; i < 10 ; i++) {
      syslogSocket = new DatagramSocket();
      syslogSocket.send(datagramPacket);
View Full Code Here

    // Write some message to the syslog port

    byte[] largePayload = getPayload(1000).getBytes();

    DatagramSocket syslogSocket;
    DatagramPacket datagramPacket;
    datagramPacket = new DatagramPacket(largePayload,
            1000,
            InetAddress.getLocalHost(), source.getSourcePort());
    for (int i = 0; i < 10 ; i++) {
      syslogSocket = new DatagramSocket();
      syslogSocket.send(datagramPacket);
View Full Code Here

     *
     * @param data gzipped GELF Message (JSON)
     */
    public void send(byte[] data) {

        DatagramPacket datagramPacket = new DatagramPacket(data, data.length, graylog2ServerAddress, graylog2ServerPort);

        sendPacket(datagramPacket);
    }
View Full Code Here

        @Override
        public void run() {
            while (!stopServer) {
                byte[] receivedData = new byte[maxPacketSize];
                DatagramPacket packet = new DatagramPacket(receivedData, maxPacketSize);
                try {
                    socket.receive(packet);
                } catch (IOException e) {
                    lastRequest = ImmutableMap.of("Error", (Object)e.getMessage());
                }
                if (receivedData[0] == (byte) 0x1f && receivedData[1] == (byte) 0x8b) {
                    String decompressed = decompressGzip(packet.getData());

                    Map map = gson.fromJson(decompressed, Map.class);
                    lastRequest = ImmutableMap.copyOf(map);// ImmutableMap.of("Zipped?", true, "length", packet.getLength(), "body", decompressed, "map", map);
                }
View Full Code Here

TOP

Related Classes of java.net.DatagramPacket

Copyright © 2018 www.massapicom. 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.