प्राप्त नहीं कर रहा हूं मैं जावा में एक कक्षा लिख रहा हूं जिसका उपयोग मल्टीकास्टिंग की प्रक्रिया को बहुत सरल बनाने के लिए किया जाता है। हालांकि, मैं इसके साथ दो बड़ी समस्याओं कर रहा हूँ:जावा मल्टीकास्ट डेटा भेज रहा है,
- वर्ग डेटा भेजता है, लेकिन डेटा एक ही समूह में किसी भी अन्य लोगों के द्वारा प्राप्त नहीं होता है (मैं अपने शुद्ध मॉनिटर, Wireshark के साथ इस की पुष्टि कर सकते हैं)।
- कुछ मशीनों पर, प्रेषण पैकेट टीटीएल पारगमन में पार हो गया है (फिर, वायरशर्क के अनुसार)।
क्या कोई मेरी मदद कर सकता है? मैं घंटों के लिए उत्तर की कोशिश कर रहा हूं और खोज रहा हूं, और ऐसा लगता है कि मेरा कोड मल्टीकास्ट होस्ट से डेटा जोड़ने, जुड़ने, भेजने और प्राप्त करने के लिए सभी मूल प्रक्रियाओं का पालन करता है।
Multicaster वर्ग:
Multicaster multicast = new Multicaster("239.0.0.0");
try {
multicast.connect();
} catch (MulticasterInitException e) {
//Handle exception...
}
multicast.joinGroup();
try {
multicast.sendData("Hi");
} catch (MulticasterSendException e) {
//Handle exception...
}
नमूना उपयोग:
public class Multicaster {
public int port = 5540;
protected String IPAddress;
private MulticastSocket msConn;
private InetAddress netAddr;
public Multicaster(String IPAddress) {
this.IPAddress = IPAddress;
}
public String recieveData() {
byte[] buf = new byte[1000];
DatagramPacket pack = new DatagramPacket(buf, buf.length);
try {
this.msConn.receive(pack);
new Message(pack);
String out = new String(pack.getData());
return out.substring(0, pack.getLength());
} catch (IOException e) {
return new String("");
}
}
public void joinGroup() {
try {
this.msConn.joinGroup(this.netAddr);
} catch (IOException e) {
//This error shouldn't occur since it would caught by the connect() method during initial connection to the host
}
}
public void connect() throws MulticasterInitException {
//Try to create a multicast connection on the given IP address and port
try {
try {
//Create a multicast connection on a given port, throws UnknownHostException
this.msConn = new MulticastSocket(this.port);
//If all goes well, then create a connection to a given IP address using the above port number, throws IOException and SecurityException
this.netAddr = InetAddress.getByName(this.IPAddress);
}
}
/**
* Here all of the possible exceptions that are thrown above
* are caught and handled here. This works just fine.
*/
}
public void sendData(String data) throws MulticasterSendException {
DatagramPacket packet = new DatagramPacket(data.getBytes(), data.length(), this.netAddr, this.port);
try {
this.msConn.send(packet);
} catch (IOException e) {
throw new MulticasterSendException("Java could not communicate with the server. Please check your network connections.", e);
}
}
}
नमूना उपयोग डेटा भेजने के लिए
यहाँ वर्ग के संबंधित भाग का एक टुकड़ा है डेटा प्राप्त करने के लिए:
Multicaster multicast = new Multicaster("239.0.0.0");
try {
multicast.connect();
} catch (MulticasterInitException e) {
//Handle exception...
}
multicast.joinGroup();
System.out.print(multicast.recieveData());
आप मेरी टिप्पणियों का उल्लेख कर सकते हैं क्योंकि यह समस्या [http://stackoverflow.com/questions/8471447/java-multicast- नमूना-program-is-unable-to-deliver-packets-within-lan- भर-हो] (http://stackoverflow.com/questions/8471447/java-multicast- नमूना-program-is-unable-to-deliver-packets-within-lan-across-ho) – ecle