Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6985567

networking - error in sample code

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 6-pool
    • docs
    • generic
    • generic

      small error in code example found at http://download.oracle.com/javase/tutorial/networking/datagrams/broadcasting.html


      public void run() {
          while (moreQuotes) {
              try {
                  byte[] buf new byte[256]; //should be: byte[] buf = new byte[256]; or am i mistaken =S
                  // don't wait for request...just send a quote

                  String dString = null;
                  if (in == null)
                      dString = new Date().toString();
                  else
                      dString = getNextQuote();
                  buf = dString.getBytes();

                  InetAddress group = InetAddress.getByName(
                                                  "230.0.0.1");
                  DatagramPacket packet;
                  packet = new DatagramPacket(buf, buf.length,
                                              group, 4446);
                  socket.send(packet);

                  try {
                      sleep((long)Math.random() * FIVE_SECONDS);
                  } catch (InterruptedException e) { }
              } catch (IOException e) {
                  e.printStackTrace();
                  moreQuotes = false;
              }
          }
          socket.close();
      }

            Unassigned Unassigned
            skannan Sowmya Kannan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: