Hi there,
I am having a problem passing an int value from one class to the other. The gist of the objective of this program is to compute a local sum at each client, and then once the local sums are computed.. to compute the overall sum from all the clients. My problem is that I'm having trouble figuring out how to pass each sum from each individual client in the class multicastSenderReceiver to the readThread class. I keep getting an error here:
Java Code:
DatagramPacket packet = new DatagramPacket(msg, msg.length, group, 
              multicastPort, sum);
This is the error I get:
Java Code:
no suitable constructor found for DatagramPacket(byte[],int,InetAddress,int,int)
    constructor DatagramPacket.DatagramPacket(byte[],int,SocketAddress) is not applicable
      (actual and formal argument lists differ in length)
    constructor DatagramPacket.DatagramPacket(byte[],int,InetAddress,int) is not applicable
      (actual and formal argument lists differ in length)
    constructor DatagramPacket.DatagramPacket(byte[],int,int,SocketAddress) is not applicable
      (actual and formal argument lists differ in length)
    constructor DatagramPacket.DatagramPacket(byte[],int,int,InetAddress,int) is not applicable
      (actual argument InetAddress cannot be converted to int by method invocation conversion)
    constructor DatagramPacket.DatagramPacket(byte[],int) is not applicable
      (actual and formal argument lists differ in length)
    constructor DatagramPacket.DatagramPacket(byte[],int,int) is not applicable
      (actual and formal argument lists differ in length)
Can anyone suggest the next step??
I feel that I have to be able to pass the sum value from each client generated in multicastSenderReceiver to the other class, because that is the only way I'll accurately be able to sum up all the values.. Am I wrong? Any help is appreciated.
Thanks!
Java Code:
package multicastsenderreceiver;

import java.net.*;
import java.io.*;
import java.util.*;
//import static multicastsenderreceiver.multicastSenderReceiver.numProcesses;

class multicastSenderReceiver{

  static int numbers[];
  static int numProcesses;
  public static int sum;

  public static void main(String[] args){

   try{
         
     numProcesses = Integer.parseInt(args[0]);

     int processID = Integer.parseInt(args[1]);

     int arraySize = Integer.parseInt(args[2]);

     numbers = new int[arraySize];

     String filename = args[3];
     
     FileReader fr = new FileReader(filename);
     BufferedReader br = new BufferedReader(fr);
     
     for (int i = 0; i < arraySize; i++){

	 numbers[i] = Integer.parseInt(br.readLine() );
     }

      for(int j = 0; j < numbers.length; j++){
          sum+=numbers[j];
      }
        
      // sum = multicastMessage.getBytes();
      int multicastPort = 9068;
      InetAddress group = InetAddress.getByName("225.4.5.6"); 
      MulticastSocket sendSocket = new MulticastSocket( );
      //launch the read thread
      
      
      System.out.println("Local ID: " + processID);
      System.out.println("The local sum is " + sum);
      String multicastMessage = "Message from Process#" + processID + ":" + 
              "Local sum is " + sum;
      byte[] msg = multicastMessage.getBytes();
      //int vsum = sum;
      
      DatagramPacket packet = new DatagramPacket(msg, msg.length, group, 
              multicastPort, sum);
	// wait for the read threads of all the processes to start, before sending the partial sum value
      System.out.print("Hit return to send message\n\n"); 
      BufferedReader ir = new BufferedReader(new InputStreamReader(System.in)); 
      ir.readLine( ); 
    readThread rt = new readThread(group, multicastPort, sum);
      rt.start();
      sendSocket.send(packet);
      // send <key, value> as a string where key is the process ID and value is the partial sum value

  


    }
   
   catch(Exception e){e.printStackTrace();}

}
  
}
class readThread extends Thread{
    InetAddress group;
    int multicastPort;
    int MAX_MSG_LEN = 10000;
   int sum;
    
    //multicastSenderReceiver vsum = new multicastSenderReceiver();
    //int vsum;
    readThread(InetAddress g, int port, int vsum ){
        group = g;
        multicastPort = port;
        sum = vsum;
        
    }
    
    public void run(){
        try{
            MulticastSocket readSocket = new MulticastSocket(multicastPort);
            readSocket.joinGroup(group);
            while(true){
                byte[] message = new byte[MAX_MSG_LEN];
                DatagramPacket packet = new DatagramPacket(message,
                        message.length,group, multicastPort, sum);
                
                readSocket.receive(packet);
                String msg = new String(packet.getData());
                System.out.println(msg);
            }
        
        }
        catch(Exception e){e.printStackTrace();}
    }
}}