السلام عليكم شباب
بالتالي كود جافا قصير جداً و بسيط ووظيفته كالتالي:- ((عفوا على الأخطاء الإملائيه, تم وضعها عن عمد))
"semple groop comunication program using the Javu class Multi Socket"
كود:
import java.net.*;
import java.io.*;
public class MulticastPeer{
public static void main(String args[]){
// args[0] = ID (or name) of the member to multicast to the group
// args[1] = IP address of the group (e.g. "228.5.6.7")
MulticastSocket s =null;
try {
System.out.println("Memeber " + args[0] + "trying to join the group");
InetAddress group = InetAddress.getByName(args[1]);
s= new MulticastSocket(6789);
s.joinGroup(group);
System.out.println("Memeber " + args[0] + "is now member of the group");
byte [] m = args[0].getBytes();
DatagramPacket msgOut = new DatagramPacket(m,m.length, group, 6789);
s.send(msgOut);
System.out.println("Memeber's ID was transmitted to the group");
System.out.println("Waiting to receive messages from other members");
byte[] buffer = new byte[1000]; // get messages from others in group
for(int i=0; i< 3;i++) {
DatagramPacket msgIn = new DatagramPacket(buffer,buffer.length);
s.receive(msgIn);
System.out.println("Received : " + new String(msgIn.getData(), 0, msgIn.getLength()));
}
s.leaveGroup(group);
System.out.println("Member " + args[0] + "left the group");
} catch (SocketException e){System.out.println("Socket: " + e.getMessage());
} catch (IOException e){System.out.println("IO: " + e.getMessage());
} finally {if(s != null) s.close();}
}
}
و المطلوب التعديل على الكود ليقوم بالتالي:-

المطلوب إرسال الـmembers للمعرف الخاص بهم "ID" + إرسال 3 رسائل "messages" و إستلام عدد لا محدود من الرسائل,,,
طبعاً الطلب و الكود سهل جداً و تافه للمتمرسين بالجافا و لا يأخذ مع الشخص أكثر من 10 دقائق و ربما أقل!! لكن للأسف نحن ما تعلمنا هذي اللغه بتاتاً "فقط C++" و يصعب علينا حل هذا التمرين
يرجى المساعده و شاكرين لكم التعاون الطيب و الكريم,,,