CNS LAB Manual Print
CNS LAB Manual Print
SEMESTER-V
Name
Roll No.
Date
Signature
Write a program for error detection and correction for 7/8 bits
Title ASCII codes using Hamming Codes or CRC.
Name
Roll No.
Date
Signature
for (i=0;i<msglen;i++) {
quot[i]=temp[0];
if(quot[i]=='0')
for (j=0;j<keylen;j++)
key[j]='0';
else
for (j=0;j<keylen;j++)
key[j]=key1[j];
for (j=keylen-1;j>0;j--) {
if(temp[j]==key[j])
rem[j-1]='0'; else
rem[j-1]='1';
}
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for (i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
printf("\nFinal data is: ");
for (i=0;i<msglen;i++)
printf("%c",input[i]);
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
printf("\n");
}
Name
Roll No.
Date
Signature
if(pc==0)
{
for(int i=0;i<p;++i)
{
if(a!=255)
{
System.out.println("received ack for frame no: "+i+" as "+a);
f[i]=true;
}
}// end of inner else
}// end of for
for(int a=0;a<p;++a)
{
if(f[a]==false)
{
System.out.println("Resending frame "+a);
out.write(a);
out.flush();
System.out.println("Waiting for ack ");
try
{
Thread.sleep(5000);
}
catch(Exception e){}
in.close();
out.close();
client.close();
ss.close();
System.out.println("Quiting");
class testclient
{
if(choice==0)
{
for(j=0;j<c;++j)
{
i=in.read(); //read all frames one by one from server
System.out.println("received frame no: "+i);
System.out.println("Sending acknowledgement for frame no: "+i);
out.write(i); //write ack to socket
out.flush();
}
out.flush();
}
else
{
for(j=0;j<c;++j)
{
i=in.read(); //read 0,1,2,3 frame
if(i==check)
{
System.out.println("received frame no: "+i);
System.out.println("Sending acknowledgement for frame no: "+i);
out.write(i); //sent ack of frame 0,1
++check;
}
else
{
in.close();
out.close();
System.out.println("Quiting");
try {
int a[] = { 30, 40, 50, 60, 70, 80, 90, 100 };
Serversocket = new ServerSocket(8011);
System.out.println("waiting for connection");
Socket client = Serversocket.accept();
dis = new DataInputStream(client.getInputStream());
dos = new DataOutputStream(client.getOutputStream());
System.out.println("The number of packets sent is:" + a.length);
int y = a.length;
dos.write(y);
dos.flush();
int k = dis.read();
dos.write(a[k]);
dos.flush();
} catch (IOException e) {
System.out.println(e);
} finally {
try {
dis.close();
dos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
ubuntu@linux:~$
import java.lang.System;
import java.net.*;
import java.io.*;
try {
int n = 0;
System.out.println(addr);
connection.getOutputStream());
connection.getInputStream());
int p = in.read();
v[i] = in.read();
System.out.println(v[i]);
//g[i] = v[i];
v[5] = -1;
if (v[i] == -1) {
n = i;
out.write(n);
out.flush();
System.out.println();
v[n] = in.read();
System.out.println("quiting");
} catch (Exception e) {
System.out.println(e);
Localhost/127.0.0.1
No of frame is:8
30
40
50
60
70
80
90
100
quitingt's
Name
Roll No.
Date
Signature
import java.util.Scanner;
class Subnet{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the ip address: ");
String ip = sc.nextLine();
String split_ip[] = ip.split("\\."); //SPlit the string after every .
String split_bip[] = new String[4]; //split binary ip
String bip = "";
String mask1="";
//Calculation of mask
double bits = (int)Math.ceil(Math.log(n)/Math.log(2)); /*eg if address = 120, log 120/log 2 gives log to
the base 2 => 6.9068, ceil gives us upper integer */
int y=(int) bits;
System.out.println("Number of bits borrowd from host to network are = "+y);
int z=8-y;
System.out.println("Number of host bits are = "+z);
Name
Roll No.
Date
Signature
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include <unistd.h>
#include<string.h>
#include <arpa/inet.h>
#include<netdb.h>
void main()
{
int b,sockfd,connfd,sin_size,l,n,len;
char buff[256];
char buff1[256];
if((sockfd=socket(AF_INET,SOCK_STREAM,0))>=0) //socket creation
printf("socket created sucessfully \n"); //on success 0 otherwise -1
bzero(buff,256);
//bzero(buff1,256);
//len=strlen(buff);
//reads msg from socket
n=read(connfd, buff, 256);
printf("msg from client:%s\n",buff);
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include <unistd.h>
#include<string.h>
#include<strings.h>
#include <arpa/inet.h>
#include <stdlib.h>
void main()
{
int b,sockfd,sin_size,con,n,len;
char buff[256];
char buff1[256];
char ip[50];
char port[10];
struct sockaddr_in servaddr;
// Socket call for socket creation: socket on sucess returns smallest integer value (3) otherwise -1
if((sockfd=socket(AF_INET,SOCK_STREAM,0))>=0)
printf("Socket Created Sucessfully \n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=inet_addr("127.0.0.1");
servaddr.sin_port=6007;
FILE *fp;
fp= fopen("/home/ubuntu/Downloads/CNL/Assg2/Assg2_b/send.txt", "w+");
//fp = fopen("file.txt", "w+");
// fclose(fp);
Input: receive.txt
this is file transfer program\00
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include <unistd.h>
#include<string.h>
#include<strings.h>
#include <arpa/inet.h>
#include <stdlib.h>
#define MAXBUFLEN 1000000
//#define buffsize 150
void main()
{
int b,sockfd,sin_size,con,n,len;
//char buff[256];
if((sockfd=socket(AF_INET,SOCK_STREAM,0))>=0)
printf("Socket Created Sucessfully \n");
struct sockaddr_in servaddr;
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=inet_addr("127.0.0.1");
servaddr.sin_port=6007;
char buffer[10000];
char c[10000];
FILE *fp;
//bzero(buffer,10000);
//bzero(c,10000);
read(sockfd, buffer, 10000);
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=inet_addr("127.0.0.1");
servaddr.sin_port=6006;
write(sockfd,&operator,10);
write(sockfd,&op1,sizeof(op1));
write(sockfd,&op2,sizeof(op2));
read(sockfd,&result,sizeof(result));
printf("Operation result from server=%d\n",result);
close(sockfd);
}
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include <unistd.h>
#include<string.h>
#include <arpa/inet.h>
void main()
{
int b,sockfd,connfd,sin_size,l,n,len;
char operator;
int op1,op2,result;
if((sockfd=socket(AF_INET,SOCK_STREAM,0))>0)
printf("socket created sucessfully\n"); //socket creation
//printf("%d\n", sockfd); //on success 0 otherwise -1
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=inet_addr("127.0.0.1");
servaddr.sin_port=6006;
//printf("%d\n",b);
write(connfd,&result,sizeof(result));
close(sockfd);
}
Name
Roll No.
Date
Signature
import socket
else:
print(addr6)
CERTIFICATE
This is to certify that the Practical Lab Manual
under the subject
Is a Bonafede work carried out by student under the supervision of Prof. S. K. Said.
and it is submitted towards the partial fulfilment of the requirement of Third Year of
Computer Engineering.
Principal