Multicast Problem

Miguel Ricardo <[email protected]>
Newsgroups gmane.comp.java.sun.rmi
Message-ID <[email protected]>
Hi!

I'm trying to send STUB's thru multicast to client applications...But
i'm getting a strange problem with multicast and serialization of
objects...For example:

SERVER SIDE:
public void runTest() throws IOException{
		MulticastSocket ms = new MulticastSocket(9000);		
		ms.joinGroup(InetAddress.getByName("224.10.10.10"));
		
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.flush();
		oos.writeObject(new String("Olá"));
		oos.flush();
		oos.close();
		
		byte[] sendBuf = bos.toByteArray();
		
				
		DatagramSocket socketudp = new DatagramSocket();												
	        DatagramPacket requestPacket = new DatagramPacket(sendBuf,
				sendBuf.length);
	
		requestPacket.setAddress(InetAddress.getByName("224.10.10.10"));
		requestPacket.setPort(9000);	
			
		DatagramPacket packet = new DatagramPacket(new byte[1000], 1000);
		
                ms.receive(packet);
	
		socketudp.send(requestPacket);
	}

CLIENT SIDE:

public void runTest() throws IOException, ClassNotFoundException{
		MulticastSocket ms = new MulticastSocket(9000);		
		ms.joinGroup(InetAddress.getByName("224.10.10.10"));
		
		byte[] recvBuf = new byte[65535];
		ByteArrayInputStream bis = new ByteArrayInputStream(recvBuf);
		DatagramPacket receivePacket = new DatagramPacket(
				recvBuf, recvBuf.length);

		DatagramSocket socket = new DatagramSocket();		
		DatagramPacket packet = new DatagramPacket(new
String("teste").getBytes(), 5);
		packet.setPort(9000);
		packet.setAddress(InetAddress.getByName("224.10.10.10"));
		socket.send(packet);
		
		ms.receive(receivePacket);
				
		ObjectInputStream ois = new ObjectInputStream(bis);
		String o = (String)ois.readObject();
		
		System.out.println("Result: " + o);
		
		receivePacket.setLength(recvBuf.length);
		
		bis.reset();
		
		ois.close();
	}

And it gives a java.io.StreamCorruptedException: invalid stream header
 But if i replace the multicastsocket with a datagramsocket it work's
fine! What seems to be the problem?? I aprecciate any help. Thanks in
advance.

Miguel

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.