WORKING OF UNICAST,MULTICAST,BROADCAST SESSIONS
SENDER
import java.io.*; import java.net.*;
class cast { public static void main(String a[])throws Exception { DataInputStream d=new DataInputStream(System.in); String id=""; String msg="msg from apl13"; char [][]grp=new char[20][20]; char [][]grp1=new char[20][20]; Socket s; int j=0; for(int i=11;i<=12;i++) { id="apl"+i; grp[j++]= id.toCharArray(); } j=0; for(int i=13;i<=14;i++) { id="apl"+i; grp1[j++]= id.toCharArray(); }System.out.println( grp[0]); System.out.println( grp[1]); System.out.println( grp1[0]); System.out.println( grp1[1]); System.out.println("Enter ur choice\n1->Unicast\n2- >Multicast\n3->Broadcast"); int ch=Integer.parseInt(d.readLine()); switch(ch) { case 1: System.out.println("UNICAST"); s=new Socket("apl13",80); OutputStream os=s.getOutputStream(); ObjectOutputStream oos=new ObjectOutputStream(os); System.out.println("Enter any msg"); msg=d.readLine();; oos.writeObject(msg); s.close(); break; case 2: System.out.println("Multicast"); System.out.println("Enter any msg"); msg=d.readLine();; for(int i=0;i<2;i++) { id=""; for(j=0;j<5;j++) id+=grp1[i][j]; s=new Socket(id,80); os=s.getOutputStream(); oos=new ObjectOutputStream(os); oos.writeObject(msg); s.close(); } break; case 3: System.out.println("BROADCAST"); System.out.println("Enter any msg"); msg=d.readLine();; for(int i=0;i<2;i++) { id=""; for(j=0;j<5;j++) id+=grp1[i][j]; s=new Socket(id,80); os=s.getOutputStream(); oos=new ObjectOutputStream(os); oos.writeObject(msg); s.close(); } for(int i=0;i<2;i++) { id=""; for(j=0;j<5;j++) id+=grp[i][j]; s=new Socket(id,80); os=s.getOutputStream(); oos=new ObjectOutputStream(os); oos.writeObject(msg); s.close(); } break;
}
} }
RECIEVER
import java.io.*; import java.net.*;
class receiver { public static void main(String a[])throws Exception { String id; ServerSocket s1=new ServerSocket(80); Socket s; InputStream is ; ObjectInputStream ios ; while(true) { s=s1.accept(); is=s.getInputStream(); ios=new ObjectInputStream(is); System.out.println(ios.readObject()); } } }
|
No feedbacks found. Be the first to respond and make money from revenue sharing program.
|