title: Multicast server receive the same data it sends
body: <p>I'm trying to allow clients that connect to my UDP server to send packets to the server, I have a server running so packets can be sent to the clients, but trying to send packets back via the client to the server seems to create some weird errors. </p>
  
  <p>If I start the server, then open a client, the client will receive the first packet from the server, the client then tries to send the packet to the server, this is received by the server, but then the client throws this error</p>
  
  <pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: "testing"
      at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
      at java.lang.Double.parseDouble(Unknown Source)
      at Pong.PongUDPClient.main(PongUDPClient.java:71)
  </code></pre>
  
  <p>Line 71 will be pointed at in the code
  The server console is just printing out the data it should be sending to the client, </p>
  
  <p>Here is the whole code for the server</p>
  
  <pre><code>package Pong;
  
  import java.io.IOException;
  import java.net.DatagramPacket;
  import java.net.DatagramSocket;
  import java.net.InetAddress;
  import java.net.MulticastSocket;
  import java.net.Socket;
  
  //This is the actual server
  public class PongUDPServerThread extends Thread {
  
  //speed to send data
  private long dataSpeed = 10;
  private int port = 4447;
  private int idPlayer = 0;
  private PongModel model;
  private PongView  view;
  private PongPlayerThread players[] = new PongPlayerThread[2];
  private MulticastSocket socket = null;
  private InetAddress group;
  private DatagramPacket packet = null;
  private int ID = 1;
  
  public PongUDPServerThread() throws IOException 
  {
      super("PongUDPServerThread");
  }
  
  public String rtnInfo()
  {
      String str;
      str = model.getBall().getX() + ":" +
            model.getBall().getY() + ":" +
            model.getBats()[0].getX() + ":" +
            model.getBats()[0].getY() + ":" +
            model.getBats()[1].getX() + ":" +
            model.getBats()[1].getY();
      return str;
  }
  
  public void setupPong() throws IOException 
  {
      System.out.println("Pong");
      model = new PongModel();
      view  = new PongView();
              new PongController( model, view );
  
      model.addObserver( view );       // Add observer to the model
  
      //view.setVisible(true);           // Display Screen
      model.makeActiveObject();        // Start play
      //start server
      socket = new MulticastSocket(port);
      InetAddress group = InetAddress.getByName("230.0.0.1");
      socket.setReuseAddress(true);
      socket.joinGroup(group);
      //socket.setReuseAddress(true);
      //Inform server user
      System.out.println("Server is running");
  }
  
  public void run()
  {
      //Server loop
      while(true)
      {
  
          //Receive the data
          try
          {
          byte[] receiveBuf = new byte[256];
          packet = new DatagramPacket(receiveBuf, receiveBuf.length);
          socket.receive(packet);
  
          String received = new String(packet.getData(), 0, packet.getLength());
  
          System.out.println(received);
          }
          catch (IOException e)
          {
  
          }
  
  
          try
          {
              byte[] buf = new byte[256];
  
              //Gather data
              buf = rtnInfo().getBytes();
              //System.out.println(buf.toString());
  
              //Send data
              packet = new DatagramPacket(buf, buf.length, InetAddress.getByName("230.0.0.1"), port);
              socket.send(packet);
  
              //Sleep the server
              try
              {
                  sleep((long)dataSpeed);
              }
              catch (InterruptedException e)
              {
  
              }
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
      }
  
      //socket.close();
  
  }
  
  }
  </code></pre>
  
  <p>Here is the client code</p>
  
  <pre><code>package Pong;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  
  public class PongUDPClient {
  
  private static int port = 4447;
  
  public static void main(String[] args) throws IOException
  {
  
      //Setup pong rdy
      PongModel model = new PongModel();
      PongView  view  = new PongView();
                        new PongController( model, view );
  
      model.addObserver( view );       // Add observer to the model
  
      String pos;
  
      model.makeActiveObject();        // Start play
      //model.clientModel();
  
      MulticastSocket socket = new MulticastSocket(port);
      //socket.setReuseAddress(true);
      InetAddress address = InetAddress.getByName("230.0.0.1");
      //Join the UDP list port
      socket.setReuseAddress(true);
      socket.joinGroup(address);
  
      DatagramPacket packet;
      view.setVisible(true);           // Display Screen
  
      System.out.println("Connected");
      //Id is sent here.
  
      while(true)
      {
  
          //Send data to server
          try
          {
              byte[] receiveBuf = new byte[256];
  
              //Gather data
              receiveBuf = "testing".getBytes();
              //System.out.println(buf.toString());
  
              //Send data
              packet = new DatagramPacket(receiveBuf, receiveBuf.length, InetAddress.getByName("230.0.0.1"), port);
              socket.send(packet);
  
              //Sleep the server
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
  
          byte[] buf = new byte[256];
          packet = new DatagramPacket(buf, buf.length);
          socket.receive(packet);
  
          String  received = new String(packet.getData(), 0, packet.getLength());
          //System.out.println("Server data: " + received);
  
          String[] posValues = received.split(":");
  
          model.getBall().setX(Double.parseDouble(posValues[0])); // &lt;-- Line 71
          model.getBall().setY(Double.parseDouble(posValues[1]));
          model.getBats()[0].setX(Double.parseDouble(posValues[2]));
          model.getBats()[0].setY(Double.parseDouble(posValues[3]));
          model.getBats()[1].setX(Double.parseDouble(posValues[4]));
          model.getBats()[1].setY(Double.parseDouble(posValues[5]));
  
          //Check for keyboard input
  
          if(PongController.moveUp == true &amp;&amp; PongController.moveDown == false)
          {
              System.out.println("Up");
              PongController.moveUp = false;
          }
          else if(PongController.moveUp == false &amp;&amp; PongController.moveDown == true)
          {
              System.out.println("Down");
              PongController.moveDown = false;
          }
          else
          {
              //serverOut.println("nothing");
          }
  
  
      }
  }
  
  }
  </code></pre>
  
  <p>Been stuck on this for awhile, and can't seem to find any tutorials on how to send packets from client to server using Multicast.</p>