Posts

Showing posts from March, 2016

Java Program to implement decimal checksum

//java program for decimal checksum import java.util.*; import java.io.*; class DjCheck1 { int i,j,k,l,m; int ans=0,ans1=0; //String pck=""; public void checksum() { System.out.println("How many message you want to send ?"); Scanner s=new Scanner(System.in); i=s.nextInt(); int msg[][]=new int[i][8]; Scanner s1=new Scanner(System.in); for(j=0;j<i;j++) { System.out.println(" Enter your decimal value: "); for(k=0;k<8;k++) { msg[j][k]=s1.nextInt(); } } for(l=0;l<i;l++) { ans=0;ans1=0; System.out.print("[ "); for(m=0;m<8;m++) { System.out.print(msg[l][m]+" , "); ans+=msg[l][m]; ans1=0-ans; } System.out.print(ans1+" ]"); if(ans+ans1==0) { System.out.print(" no error."); } else { System.out.print(" error in your message."); } System.out.println(); }

Java Program to implement binary checksum

//java program for binary checksum import java.util.*; import java.io.*; class DjCheck1 { int i,j,k,l,m,n; String and=""; String compl=""; int ans; public void checksum() { int[] msg1=new int[8]; int[] msg2=new int[8]; Scanner s=new Scanner(System.in); System.out.println(" Enter your 1st binary value [8 bit]: "); for(i=0;i<8;i++) // to get values { msg1[i]=s.nextInt(); } System.out.println(" Enter your 2nd binary value [8 bit]: "); for(j=0;j<8;j++) { msg2[j]=s.nextInt(); } System.out.print("\nValue 1: "); for(k=0;k<8;k++) // to print values { System.out.print(msg1[k]); } System.out.print("\nValue 2: "); for(l=0;l<8;l++) { System.out.print(msg2[l]); } for(m=0;m<8;m++) // for 1s complement { and+=msg1[m] & msg2[m]; if(and.charAt(m)=='0') compl+="1"; else c

Java Program for block parity

/*java program for block parity or double parity (block parity). Calculating each column of multiple messages to check if it is even or odd. In Case of even value add 1 otherwise 0 to make even parity of column  eg. 10110101 11110011 _________ 01000110 */ import java.util.*; class DjParity1 { int i,j,k,l; String ans=""; public void blockParity() { System.out.println("How many message you want to send: "); Scanner s=new Scanner(System.in); i=s.nextInt(); String msg[]=new String[i]; Scanner s1=new Scanner(System.in); for(j=0;j<i;j++) { System.out.println("Enter your msg value[0/1] 8 bit: "); msg[j]=s1.nextLine(); } for(k=0;k<msg[0].length();k++) { //System.out.println("hello "+msg[k]); int a=0; for(l=0;l<i;l++) { a+=msg[l].charAt(k); //System.out.println("Your msg: "+msg[l]); } if(a%2==0) { ans+="0"; } else

Java Program for protocol 3 with two way communication between sender and receiver

/*Here, sender will send message to receiver and wait for acknowledgment for some time(here 3 sec). If receiver failed to response acknowledgement, sender resend the same message(here, 3 times). */ //sender to send message for protocol 3 import java.io.*; import java.net.*; public class protocol3_Sender { public static void main(String args[]) { try { Socket s=new Socket("localhost",6666); DataOutputStream dos=new DataOutputStream(s.getOutputStream()); DataInputStream dis=new DataInputStream(s.getInputStream()); BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str="",ack="",ch=""; do { System.out.println("Enter your message: "); str=br.readLine(); System.out.println("String: "+str); dos.writeUTF(str); ack=dis.readUTF(); for(int i=0;i<3;i++) { Thread.sleep(3000); if(ack.equals(""))

Java Program for protocol 2 with two way communication between sender and receiver until receiver response some signal.

//sender to send message for protocol 1 import java.io.*; import java.net.*; public class protocol2_Sender { public static void main(String args[]) { try { Socket s=new Socket("localhost",6666); DataOutputStream dos=new DataOutputStream(s.getOutputStream()); DataInputStream dis=new DataInputStream(s.getInputStream()); BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str="",signal=""; do { System.out.println("Sender: "); str=br.readLine(); System.out.println("String: "+str); dos.writeUTF(str); //dos.writeUTF(ch); //dos.flush(); signal=dis.readUTF(); System.out.println("Server says: " +signal); }while(signal.equals("signal")); //dos.flush(); dos.close(); //s.close(); } catch(IOException e) { System.out.println(e.getMessage()); } } } //receiver to

Java Program for protocol 1 with one side communication from sender to receiver assuming that receiver always receives the message.

//sender to send message for protocol 1 import java.io.*; import java.net.*; public class protocol1_Sender { public static void main(String args[]) { try { Socket s=new Socket("localhost",6666); DataOutputStream dos=new DataOutputStream(s.getOutputStream()); DataInputStream dis=new DataInputStream(s.getInputStream()); BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str="",ch=""; do { System.out.println("Sender: "); str=br.readLine(); System.out.println("String: "+str); dos.writeUTF(str); System.out.println("press 1 to continue.. "); ch=br.readLine(); dos.writeUTF(ch); //str1=dis.readUTF(); //System.out.println("Server says: " +str1); }while(ch.equals("1")); dos.flush(); dos.close(); //s.close(); } catch(IOException e)

List of Java Programs for Binary Conversion (CCN-Computer Communication Networking GLS Msc-it 2016)

1. Java program to implement bitwise operator. 2. Java program to convert a decimal to binary using bitwise operator. 3. Java program for Decimal to binary masking (with array and String). 4. Program to convert decimal to binary and insert bit value in it to get back the new decimal value-Static way. 5. Java program to extract bit value. 6. java program to count char for string output as framing-data link layer. 7. Java program to implement bit stuffing. 8. Java program to implement byte stuffing. 9. Java program to represent how parity bit works. //1. Java program to implement bitwise operator. class DjOp { public static void main(String args[]) { int a=60; int b=13; System.out.println("\n Bitwise AND: "+(a & b)); System.out.println("\n Bitwise OR: "+(a | b)); System.out.println("\n Bitwise XOR: "+(a ^ b)); System.out.println("\n Bitwise Compliment: "+(~a)); System.out.println("\n