3 Replies - 540 Views - Last Post: 29 November 2012 - 04:26 PM Rate Topic: -----

#1 fredd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-November 12

Capturing udp multicast - java

Posted 29 November 2012 - 02:25 PM

hi all
Im pretty new to all this , im trying to get a program working to capture a UDP multicast and write it to a text file . The multicast will be sent over specific port , if i use an application to send directly to my ip it works
but not actually capturing the multicast when just sent out for anyone to pick up .

I cannot change my subnet in program get the following error : java.net.BindException: Cannot assign requested address: Cannot bind

Please see my code below any assistance will be appreciated been battling for weeks now on same problem :stupid:
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.io.*;
public class UdpReceive {
	
	@SuppressWarnings("resource")
	public static void main(String args[]) throws IOException {
		//user defines ports
		System.out.println("please enter listning port ");
		BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
		String userPortNumber = bufferedreader.readLine();
		int port = Integer.parseInt(userPortNumber);
		System.out.println ("now listning and writing data to files");
		
	  try {
      //int port = 4050;
      String subnet = ("0.0.0.0");
      // Create a socket to listen on the port
	DatagramSocket dsocket = new DatagramSocket(port, InetAddress.getByName(subnet));
      // Create a buffer to read data into. If a
      // packet is larger than this buffer, the
      // excess will simply be discarded!
      byte[] buffer = new byte[2048];
      // Create a packet to receive data into the buffer
      DatagramPacket packet = new DatagramPacket(buffer, buffer.length);

      // Now loop forever, waiting to receive packets and printing them.
      while (true) {
        // Wait to receive a data
        dsocket.receive(packet);
  


Is This A Good Question/Topic? 0
  • +

Replies To: Capturing udp multicast - java

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2689
  • View blog
  • Posts: 11,350
  • Joined: 20-September 08

Re: Capturing udp multicast - java

Posted 29 November 2012 - 02:54 PM

Why not just use your local ip address?
Was This Post Helpful? 0
  • +
  • -

#3 fredd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-November 12

Re: Capturing udp multicast - java

Posted 29 November 2012 - 04:00 PM

I dont think if i use my local IP i will catch multicast from other machines , the application is to catch point of sale transactions broadcast over network to allow various services to capture data and use as needed , will give that a try and see

thanks
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2689
  • View blog
  • Posts: 11,350
  • Joined: 20-September 08

Re: Capturing udp multicast - java

Posted 29 November 2012 - 04:26 PM

Difficult to know without knowing how your network is set up
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1