Friday, 27 March 2015
Friday, 13 March 2015
Socket Program in Java[Client Server Program]
Description:Client program accepts a number from the user and passes it to the server, the server performs as simple mathematical operation like addition of the number with digit 5.
Video Tutorial:
Source Code://CLASS CLI
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
public class cli {
public static void main(String args[]) throws UnknownHostException, IOException
{
int number,temp;
Socket s=new Socket("127.0.0.1",1001);
Scanner sc=new Scanner(System.in);
Scanner sc1=new Scanner(s.getInputStream());
System.out.println("Enter any number");
number=sc.nextInt();
PrintStream p=new PrintStream(s.getOutputStream());
p.println(number);
temp=sc1.nextInt();
System.out.println(temp);
}
}
//Class Ser
import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class ser {
public static void main(String args[]) throws IOException
{
int n1,n2;
ServerSocket s1=new ServerSocket(1001);
Socket ss=s1.accept();
Scanner sc=new Scanner(ss.getInputStream());
n1=sc.nextInt();
PrintStream p=new PrintStream(ss.getOutputStream());
n2=n1+5;
p.println(n2);
}
}
Conflation Algorithm Code [Commented]
#include<stdio.h>
#include<string.h>
void main()
{
FILE *fptr1,*fptr2,*fptr3,*fptr4,*fptr5,*fptr6,*fptr7;
char ch[30],stop[30],temp[30],temp1[30];
int flag=0,i=0,j=0;
/*===============CONFLATION ALGORITHM PART -1 REMOVAL OF STOP WORDS FROM A FILE===========================*/
//SOURCE FILE INPUT.TXT CONTAINS NORMAL WORDS AS WELL AS STOP WORDS
//THE FILE STOP.TXT CONTAINS A LIST OF STOP WORDS
//THE STOP WORDS FROM FIRST FILE ARE REMOVES AND REMAINING WORDS ARE STORED IN THE FILE NAMED OUTPUT1.TXT
fptr1=fopen("input.txt","r");
fptr3=fopen("output1.txt","w");
while(fscanf(fptr1,"%s",ch)!=EOF)
{
fptr2=fopen("stop.txt","r");
while(fscanf(fptr2,"%s",stop)!=EOF)
{
if(strcmp(ch,stop)==0)
{
flag=1; //WHEN FLAG IS SET TO 1 MEANS THAT STOP WORD HAS BEEN FOUND
}
}
if(flag==1)
{
flag=0; //FLAG NEEDS TO BE RESET TO VALUE 1
}
else if(flag==0)
{
fprintf(fptr3,"%s\n",ch); //FLAG IS 0 MEANING THE WORD IS NOT A STOP WORD
}
}
fclose(fptr1);
fclose(fptr2);
fclose(fptr3);
/*==============================CONFLATION ALGOORITHM PART 2 , SUFFIX STRIPPING==============================================*/
fptr4=fopen("output1.txt","r");
fptr5=fopen("output2.txt","w");
while(fscanf(fptr4,"%s",temp)!=EOF)
{
i=0;
i=strlen(temp);
i--;
//REMOVING THE PLURAL WORDS S
if(temp[i]=='s')
{
temp[i]='\0';
}
//REMOVING ED TYPE
else if(temp[i]=='d')
{
if(temp[--i]=='e')
{
temp[i]='\0';
temp[++i]='\0';
}
}
//REMOVING LY
else if(temp[i]=='y')
{
if(temp[--i]=='l')
{
temp[i]='\0';
temp[++i]='\0';
}
}
//REMOVING ING
else if(temp[i]=='g')
{
if(temp[--i]=='n')
{
if(temp[--i]=='i')
{
temp[i]='\0';
temp[++i]='\0';
temp[++i]='\0';
}
}
}
fprintf(fptr5,"%s\n",temp);
}
fclose(fptr5);
/*====================CONFLATION ALGORITHM STEP 3 , DETECTION OF EQUIVALENT STEMS======================*/
flag=0;
fptr6=fopen("output2.txt","r");
while(fscanf(fptr6,"%s",temp)!=EOF)
{
fptr7=fopen("output3.txt","r+");
while(fscanf(fptr7,"%s",temp1)!=EOF)
{
if(strcmp(temp,temp1)==0)
{
flag=1;
}
}
if(flag==1)
{
flag=0;
}
else if(flag==0)
{
fprintf(fptr7,"\n%s",temp);
printf("%s",temp);
}
fclose(fptr7);
}
fclose(fptr6);
//fclose(fptr7);
}
#include<stdio.h>
#include<string.h>
void main()
{
FILE *fptr1,*fptr2,*fptr3,*fptr4,*fptr5,*fptr6,*fptr7;
char ch[30],stop[30],temp[30],temp1[30];
int flag=0,i=0,j=0;
/*===============CONFLATION ALGORITHM PART -1 REMOVAL OF STOP WORDS FROM A FILE===========================*/
//SOURCE FILE INPUT.TXT CONTAINS NORMAL WORDS AS WELL AS STOP WORDS
//THE FILE STOP.TXT CONTAINS A LIST OF STOP WORDS
//THE STOP WORDS FROM FIRST FILE ARE REMOVES AND REMAINING WORDS ARE STORED IN THE FILE NAMED OUTPUT1.TXT
fptr1=fopen("input.txt","r");
fptr3=fopen("output1.txt","w");
while(fscanf(fptr1,"%s",ch)!=EOF)
{
fptr2=fopen("stop.txt","r");
while(fscanf(fptr2,"%s",stop)!=EOF)
{
if(strcmp(ch,stop)==0)
{
flag=1; //WHEN FLAG IS SET TO 1 MEANS THAT STOP WORD HAS BEEN FOUND
}
}
if(flag==1)
{
flag=0; //FLAG NEEDS TO BE RESET TO VALUE 1
}
else if(flag==0)
{
fprintf(fptr3,"%s\n",ch); //FLAG IS 0 MEANING THE WORD IS NOT A STOP WORD
}
}
fclose(fptr1);
fclose(fptr2);
fclose(fptr3);
/*==============================CONFLATION ALGOORITHM PART 2 , SUFFIX STRIPPING==============================================*/
fptr4=fopen("output1.txt","r");
fptr5=fopen("output2.txt","w");
while(fscanf(fptr4,"%s",temp)!=EOF)
{
i=0;
i=strlen(temp);
i--;
//REMOVING THE PLURAL WORDS S
if(temp[i]=='s')
{
temp[i]='\0';
}
//REMOVING ED TYPE
else if(temp[i]=='d')
{
if(temp[--i]=='e')
{
temp[i]='\0';
temp[++i]='\0';
}
}
//REMOVING LY
else if(temp[i]=='y')
{
if(temp[--i]=='l')
{
temp[i]='\0';
temp[++i]='\0';
}
}
//REMOVING ING
else if(temp[i]=='g')
{
if(temp[--i]=='n')
{
if(temp[--i]=='i')
{
temp[i]='\0';
temp[++i]='\0';
temp[++i]='\0';
}
}
}
fprintf(fptr5,"%s\n",temp);
}
fclose(fptr5);
/*====================CONFLATION ALGORITHM STEP 3 , DETECTION OF EQUIVALENT STEMS======================*/
flag=0;
fptr6=fopen("output2.txt","r");
while(fscanf(fptr6,"%s",temp)!=EOF)
{
fptr7=fopen("output3.txt","r+");
while(fscanf(fptr7,"%s",temp1)!=EOF)
{
if(strcmp(temp,temp1)==0)
{
flag=1;
}
}
if(flag==1)
{
flag=0;
}
else if(flag==0)
{
fprintf(fptr7,"\n%s",temp);
printf("%s",temp);
}
fclose(fptr7);
}
fclose(fptr6);
//fclose(fptr7);
}
Subscribe to:
Posts (Atom)