Character Count - Framing Technics
Sender
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main()
{
int Frame_Count,j=0,len,i,k,pid;
char Frame_Data[50],targeted_frame[100];
system("clear");
system(">pipe");
pid=open("pipe",O_WRONLY);
printf("How many Frame you data want to send : ");
scanf("%d",&Frame_Count);
for(i=0;i<Frame_Count;i++)
{
printf("\nEnter Frame [%d] : ",i);
scanf("%s",Frame_Data);
len=strlen(Frame_Data);
targeted_frame[j]=len+1+48; //set Header [header + total char followed by header]
for(k=0;k<len;k++)
{
j++;
targeted_frame[j]=Frame_Data[k];
}
j++;
}
targeted_frame[j]='\0';
printf("\nFRAME TO SEND : %s",targeted_frame);
write(pid,&targeted_frame,sizeof(targeted_frame));
}
/*2i5love6india*/
Receiver
#include<fcntl.h>
#include<stdio.h>
#include<string.h>
void main()
{
int no,j=0,len,i=0,k,pid;
char Frame_Data[50],targeted_frame[100];
system("clear");
pid=open("pipe",O_RDONLY);
read(pid,&targeted_frame,sizeof(targeted_frame));
while(targeted_frame[i]!='\0')
{
len=targeted_frame[i]-48;
i++;
for(k=0;k<len-1;k++)
{
Frame_Data[k]=targeted_frame[i];
i++;
}
Frame_Data[k]='\0';
printf("\nFrame received : %s\n",Frame_Data);
}
}
/*
i love india
*/
Code using command line argument
Sender
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main(int c, char *argv[])
{
int Frame_Count,j=0,len,i,k,pid;
char Frame_Data[50],targeted_frame[100];
char myPipe[50];
// concatenation of > with pipe name available in command line argument number one
sprintf(myPipe, "%s%s", ">", argv[1]);
system("clear");
system(myPipe);
pid=open(argv[1],O_WRONLY);
printf("How many Frame you data want to send : ");
scanf("%d",&Frame_Count);
for(i=0;i<Frame_Count;i++)
{
printf("\nEnter Frame [%d] : ",i);
scanf("%s",Frame_Data);
len=strlen(Frame_Data);
targeted_frame[j]=len+1+48; //set Header [header + total char followed by header]
for(k=0;k<len;k++)
{
j++;
targeted_frame[j]=Frame_Data[k];
}
j++;
}
targeted_frame[j]='\0';
printf("\nFRAME TO SEND : %s",targeted_frame);
write(pid,&targeted_frame,sizeof(targeted_frame));
}
#include<fcntl.h>
#include<string.h>
void main(int c, char *argv[])
{
int Frame_Count,j=0,len,i,k,pid;
char Frame_Data[50],targeted_frame[100];
char myPipe[50];
// concatenation of > with pipe name available in command line argument number one
sprintf(myPipe, "%s%s", ">", argv[1]);
system("clear");
system(myPipe);
pid=open(argv[1],O_WRONLY);
printf("How many Frame you data want to send : ");
scanf("%d",&Frame_Count);
for(i=0;i<Frame_Count;i++)
{
printf("\nEnter Frame [%d] : ",i);
scanf("%s",Frame_Data);
len=strlen(Frame_Data);
targeted_frame[j]=len+1+48; //set Header [header + total char followed by header]
for(k=0;k<len;k++)
{
j++;
targeted_frame[j]=Frame_Data[k];
}
j++;
}
targeted_frame[j]='\0';
printf("\nFRAME TO SEND : %s",targeted_frame);
write(pid,&targeted_frame,sizeof(targeted_frame));
}
/*2i5love6india*/
Receiver
#include<fcntl.h>
#include<stdio.h>
#include<string.h>
void main(int c, char *argv[])
{
int no,j=0,len,i=0,k,pid;
char Frame_Data[50],targeted_frame[100];
system("clear");
if (pid <= 0)
{
printf("Pipe does not exist. \n");
exit(1);
}
else
{
read(pid,&targeted_frame,sizeof(targeted_frame));
while(targeted_frame[i]!='\0')
{
len=targeted_frame[i]-48;
i++;
for(k=0;k<len-1;k++)
{
Frame_Data[k]=targeted_frame[i];
i++;
}
Frame_Data[k]='\0';
printf("\nFrame received : %s\n",Frame_Data);
}
}
}
/*
i love india
*/
How to run:
Compile sender
gcc sender.c -o sen
Execute sender
./sen
Compile receiver
gcc receiver.c -o rec
Execute receiver
./rec
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
2 comments:
Thanks for this character counter code, i want to try this very soon......
thanks..bhai
Post a Comment