aspose file tools*
The moose likes Beginning Java and the fly likes Multicasting Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Multicasting Problem" Watch "Multicasting Problem" New topic
Author

Multicasting Problem

Vlad Bozic
Greenhorn

Joined: Oct 31, 2003
Posts: 1
G'day people )
Since I am a newbie here and this is my first post here, please dont kick me out just yet.
I have just started learning Java, from lots of samples, and from books and I have been interested in the topic of multitasking. The snippet bellow allows me to send the message to the group, but when I get reply from someone in the group, I can see the previous message. Foe example, lets say Joe sends me a string "Have a nice day", and I display it on the screen, and then when some other Joe sends me a string i.e. "-----bye", the display is "-----byeice", so the first part of the original string gets replaced. I have tried empying the buffer, resetting couple other things around, but to no avail.
I am sure I am just missing a line or two, so any pointer in the right direction is more than appreciated.
[snippet]
byte[] buffer = new byte[1024];
for(;;) { // get messages from others in group, infinite loop
DatagramPacket messageIn = new DatagramPacket(buffer, buffer.length);
s.receive(messageIn);

System.out.println("Received:" + new String(messageIn.getData()));

System.out.println ("Enter the message: ");
msg = inFromUser.readLine();
//By typing 'exit' user gets outta Multicast Group
if (msg.equals("exit"))
break;
m = msg.getBytes ();
messageOut = new DatagramPacket(m, m.length, group, 6789);
s.send(messageOut);
}s.leaveGroup(group);
Thanks a lot
Vlad
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Try moving the byte array declaration inside th 'for' loop so it gets recreated each time rather than re-used.
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multicasting Problem