Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 3rd, 2008, 04:36 PM
Sleep Mode's Avatar
Sleep Mode Sleep Mode is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 122 Sleep Mode User rank is Corporal (100 - 500 Reputation Level)Sleep Mode User rank is Corporal (100 - 500 Reputation Level)Sleep Mode User rank is Corporal (100 - 500 Reputation Level)Sleep Mode User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 50 m 35 sec
Reputation Power: 6
Java Multicast Socket problem

Hi.
I am developing a peer to peer system that works under the same subnet.
I use Java Multicast Socket for broadcasting UDP messages.

But i have a problem. In a laboratory with PCs, at first i use 2 of them to be peers to test and i run my program on them. In only 1/15 tries, the message i broadcasted from one peer is received from the other peer. For the rest 14 tries, the peer is receiving nothing.

I get the code from java.sun.com and i think the code shouldn't be incorrect, i am posting here:

Code:
 String msg = "Hello";
 InetAddress group = InetAddress.getByName("228.5.6.7");
 MulticastSocket s = new MulticastSocket(6789);
 s.joinGroup(group);
 DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),group, 6789);
 s.send(hi);
 // get their responses!
 byte[] buf = new byte[1000];
 DatagramPacket recv = new DatagramPacket(buf, buf.length);
 s.receive(recv);


There is no router between the 2 hosts that run this program.
What am i doing wrong here?

The peers should send and receive broadcast messages. But why do they make it successful in 1/15 tries only. If that 1 successful try wouldn't happened, i would have thought that there's a problem with the LAN. But sometimes, very oftenly, the peer receives the broadcast. Why?

And i might not understood the Class D IP and multicast concept. That ip number : "228.5.6.7" is not a real ip address that represents a host. That is a special virtual ip for specifying "groups". Once a peer joined to that group (it does not connect to any server, does it?), it can receive all the broadcast messages that are sent to that group. But it can get only few of them? Why?

Thanks for any help..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Java Multicast Socket problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway