Visual identity

If you want promote your business, then you have come to the right place. more »

Unique solutions

If you want promote your business, then you have come to the right place. more »

Live support

If you want promote your business, then you have come to the right place. more »

Java Code For FTP Using UDP

Posted by Unknown
Java Code For FTP Using UDP













//server
import java.io.*;
import java.net.*;

class FTPUDPS
{
    public static void main(String[] args)
    {
                DatagramSocket socket=null;
                //Send, Receive packets
                DatagramPacket inPacket=null;
                DatagramPacket outPacket=null;
                byte[] inBuf, outBuf;
                final int PORT=50000;

                try
                {
                        socket=new DatagramSocket(PORT);
                        while(true)
                        {
                                System.out.println("\nRunning...\n");

                                //Receive Client's request
                                inBuf=new byte[100];
                                inPacket=new DatagramPacket(inBuf, inBuf.length);
                                socket.receive(inPacket);

                                //Get Port and IPAddress
                                int source_port=inPacket.getPort();
                                InetAddress source_address=inPacket.getAddress();
                                System.out.println("Client: "+source_address + ":" + source_port);

                                //Send File list
                                String dirname="/home/vaibhav/TextFiles/";
                                File f1=new File(dirname);
                                File fl[]=f1.listFiles();

                                StringBuilder sb=new StringBuilder("\n");
                                int c=0;

                                for(int i=0;i<fl.length;i++)
                                {
                                        if(fl[i].canRead() && (fl[i].toString()).endsWith(".txt"))
                                        c++;
                                }

                                sb.append(c+" .txt files found.\n\n");

                                for(int i=0;i<fl.length;i++)
                                        if((fl[i].toString()).endsWith(".txt"))       
                                                sb.append(fl[i].getName()+" "+fl[i].length()+" Bytes\n");

                                sb.append("\nEnter file name for download: ");
                                outBuf=(sb.toString()).getBytes();
                                outPacket=new DatagramPacket(outBuf, 0, outBuf.length, source_address, source_port);
                                socket.send(outPacket);

                                //Receive Filename request
                                inBuf=new byte[100];
                                inPacket=new DatagramPacket(inBuf, inBuf.length);
                                socket.receive(inPacket);
                                String filename=new String(inPacket.getData(), 0, inPacket.getLength());

                                System.out.println("Requested File: "+filename);

                                boolean flis=false;
                                int index=-1;
                                sb=new StringBuilder("");
                                for(int i=0;i<fl.length;i++)
                                {
                                        if(((fl[i].getName()).toString()).equalsIgnoreCase(filename))
                                        {
                                                index=i;
                                                flis=true;
                                        }

                                }

                                if(!flis)
                                {
                                        System.out.println("ERROR");
                                        sb.append("ERROR");
                                        outBuf=(sb.toString()).getBytes();
                                        outPacket=new DatagramPacket(outBuf, 0, outBuf.length, source_address, source_port);
                                        socket.send(outPacket);
                                }
                                else
                                {
                                        try
                                        {
                                                //File Send Process, Independent
                                                File ff=new File(fl[index].getAbsolutePath());
                                                FileReader fr=new FileReader(ff);
                                                BufferedReader brf=new BufferedReader(fr);      
                                                String s=null;
                                                sb=new StringBuilder();

                                                while((s=brf.readLine())!=null)
                                                {
                                                        sb.append(s);
                                                }

                                                if(brf.readLine()==null)
                                                        System.out.println("File Read Successful. Closing Socket.");
                                                       
                                                outBuf=(sb.toString()).getBytes();
                                                outPacket=new DatagramPacket(outBuf, 0, outBuf.length, source_address, source_port);
                                                socket.send(outPacket);    
                                        }
                                        catch(IOException ioe)
                                        {
                                        System.out.println(ioe);
                                        }
                                }
                        }
                }
               
                catch(Exception e)
                {
                        System.out.println("Error\n");
                }
    }
}

//client
import java.io.*;
import java.net.*;
import java.util.Scanner;

class FTPUDPC
{
    public static void main(String[] args)
    {
                DatagramSocket socket = null;
                DatagramPacket inPacket = null;
                DatagramPacket outPacket = null;
                byte[] inBuf, outBuf;
                final int PORT = 50000;
                String msg = null;
                Scanner src=new Scanner(System.in);

                try
                {
                        InetAddress address = InetAddress.getByName("127.0.0.1");
                        socket = new DatagramSocket();

                        msg = "";
                        outBuf = msg.getBytes();
                        outPacket = new DatagramPacket(outBuf, 0, outBuf.length, address, PORT);
                        socket.send(outPacket);

                        inBuf = new byte[65535];
                        inPacket = new DatagramPacket(inBuf, inBuf.length);
                        socket.receive(inPacket);

                        String data = new String(inPacket.getData(), 0, inPacket.getLength());
                        //Print file list
                        System.out.println(data);

                        //Send file name
                        String filename=src.nextLine();             
                        outBuf = filename.getBytes();
                        outPacket = new DatagramPacket(outBuf, 0, outBuf.length,address, PORT);
                        socket.send(outPacket);

                        //Receive file
                        inBuf = new byte[100000];
                        inPacket = new DatagramPacket(inBuf, inBuf.length);
                        socket.receive(inPacket);

                        data = new String(inPacket.getData(), 0, inPacket.getLength());
                        if(data.endsWith("ERROR"))
                        {
                                System.out.println("File doesn't exist.\n");
                                socket.close();
                        }
                        else
                        {
                                try
                                {
                                        BufferedWriter pw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename)));
                                        pw.write(data);
                                        //Force write buffer to File
                                        pw.close();

                                        System.out.println("File Write Successful. Closing Socket.");
                                        socket.close();
                                }
                                       
                                catch(IOException ioe)
                                {
                                        System.out.println("File Error\n");
                                        socket.close();
                                }
                        }
                }
                catch (Exception e)
                {
                        System.out.println("\nNetwork error. Please try again.\n");
                }
    }
}


more »

Java Code For FTP Using TCP

Posted by Unknown
Java Code For FTP Using TCP














//Server
import java.io.*;
import java.net.*;
import java.util.Arrays;

class FileSend
{
        public static void main(String args[])
        {
                //Keep trying until Client connects.
                try
                {
                        ServerSocket serversocket=new ServerSocket(50000);
                        //Created ServerSocket on port 50000. Acknowledge client.
                        System.out.println("Running...");
                        //Accept incoming Client request.
                        Socket socket=serversocket.accept();
                        System.out.println("Client connected.");
                       
                        //Read and Write on Socket.
                        PrintWriter pw=new PrintWriter(socket.getOutputStream());
                        BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
                       
                        //Send File List
                        String dirname="/media/VA/ACN/TextFiles";
                        File f1=new File(dirname);
                        File fl[]=f1.listFiles();
                       
                        //Sort Alphabetically
                        Arrays.sort(fl);
                       
                        //Counter for required files
                        int c=0;

                        for(int i=0;i<fl.length;i++)
                        {
                                if(fl[i].canRead() && (fl[i].toString()).endsWith(".txt"))
                                        c++;
                        }
                       
                        pw.println(" "+c+" .txt files found, listed A-Z.");

                        for(int i=0;i<fl.length;i++)
                              if((fl[i].toString()).endsWith(".txt"))       
                                        pw.println(" "+fl[i].getName()+" "+fl[i].length()+" Bytes");

                        //Output String Stream delimiter
                        pw.println("~");
                        pw.flush();
                       
                        //Convert ASCII to Decimal value.
                        String tem=br.readLine();                       
                        int temp=Integer.parseInt(tem);
                        temp-=49;
                        System.out.println("Index: "+temp);
                       
                        //Check if file exists
                        boolean flis=false;
                        int index=0;
                               
                        if(temp>=0 && temp<=fl.length)
                        {
                                flis=true;
                                index=temp;
                        }
                        else
                                flis=false;
                               
                        if(flis)
                        {
                                try
                                {
                                        //File Send Process, Independent
                                        File ff=new File(fl[index].getAbsolutePath());
                                        FileReader fr=new FileReader(ff);
                                        BufferedReader brf=new BufferedReader(fr);      
                                        String s;

                                        while((s=brf.readLine())!=null)
                                                pw.println(s);
                                        //Force write buffer to Client
                                        pw.flush();
                                       
                                        if(brf.readLine()==null)
                                                System.out.println("File Read Successful. Closing Socket.");                               
                                }
                                catch(IOException ioe)
                                {
                                        System.out.println("\nError in FTP. Please try again.");
                                }
                        }                       
                       
                        //Close streams and socket.
                        br.close();
                        socket.close();
                }
                catch(Exception E)
                {
                        System.out.println("\nConnection error, please try again.");
                }
        }
}

//client
import java.io.*;
import java.net.*;

class FileReceive
{
        public static void main(String args[])
        {
                try
                {
                        Socket socket=new Socket("127.0.0.1", 50000);
                       
                        //Read and Write on Socket.
                        PrintWriter out=new PrintWriter(socket.getOutputStream());
                        BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
                       
                        //Read from Console
                        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
                       
                        String s;
                       
                        while((br.read())!='~')
                                System.out.println(br.readLine());
                       
                        System.out.println("Enter file index no: ");
                        out.println(bu.read());
                        //Force write buffer
                        out.flush();
                       
                        //File Receive Process, Independent
                        try
                        {
                                BufferedWriter pw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("Received.txt")));
                               
                                while((s=br.readLine())!=null)
                                        pw.write(s);
                                //Force write buffer to Server
                                pw.close();
                               
                                if(br.readLine()==null)
                                        System.out.println("File Write Successful. Closing Socket.");
                        }
                        catch(IOException ioe)
                        {
                        }
                }
                catch(Exception E)
                {
                        System.out.println("Server is down, please try again later.");
                }
        }
}
more »

HTC One(M8) launched in India For Rs 49,900

Posted by Unknown

HTC One(M8) launched in India For Rs 49,900

In the wake of proclaiming its new leader gadget just about a month back, HTC today propelled the One (M8) in India today. The One (M8) has been evaluated at Rs 49,900 and will be accessible from May 7. HTC additionally uncovered that the Google Play Edition of the One (M8) will be accessible for preorder today, and will be accessible for buy a couple of weeks after the fact on the Google Play Store. This might make it the first Google Play Edition gadget to be accessible in India.

To recap on the specifications, the One (M8) flaunts a 5-inch 1080p presentation with pixel thickness of 441ppi and Gorilla Glass 3 protection. It is fueled by a Snapdragon 801 quad-center processor timed at 2.5GHz and combined with Adreno 330 GPU and 2gb of RAM. Likewise included, is 16gb inner stockpiling that might be stretched to up to 128gb utilizing a microsd card. On the off chance that that is insufficient, purchasers will additionally get 50gb of extra Google Drive space.

The idea of the One (M8) is the Duo Camera at the back, which is basically a 4-Ultrapixel essential Polaroid with double LED blaze and an alternate module, which fills in as a profundity sensor. This sensor measures the separation between articles/subjects in the casing and later permits clients to change the center in the photograph. For selfies, the telephone dons a 5-megapixel front-confronting Polaroid with BSI sensor and f/2.0 gap for a finer photography experience. Notwithstanding that HTC has included various new altering characteristics including the fun altering mode to the telephone.

Connectivity choices incorporate 4G-LTE help on 2,300MHz band, which works in India, 3G backing, NFC, Bluetooth, Wi-Fi and GPS. Also, the gadget additionally underpins FDD-LTE systems, which will permit clients in India to get access to 4G system even while on international roaming in most of the countries. Other features include a 2,600mAh battery with a power saving mode, which extends the battery life to two weeks.

more »

Java Code For Nearest Neighbor classifier

Posted by Unknown
Java Code For Nearest Neighbor classifier
















import java.io.*;
importjava.util.*;
importjava.math.*;
public class KNN
{
Scanner src=new Scanner(System.in);
introwcount=0,colcount;
String f[][];
intcolvar=0;
float[] newcol;
float[] requirement;
String[] req;
double[] dist;
intT,pos;
float min=0.0f,max=0.0f;

void display()
{
for(int q=0;q<rowcount;q++)
{
for(int s=0;s<colcount;s++)
System.out.print(f[q][s]+"\t");
System.out.println();
}
}//display-------------------------------------------
void newcolcal()
{
System.out.println("Enter column name");
String tempstr=src.nextLine();
for(int q=0;q<colcount;q++)
if(f[0][q].equals(tempstr))
colvar=q;
}//newcolcal-----------------------------------------

void normal()
{
int flag=0;
for(int q=1;q<rowcount;q++)
{
newcol[flag]=Float.parseFloat(f[q][colvar]);
flag++;
}
                for(int q=0;q<newcol.length;q++)
                if(max<newcol[q])
                max=newcol[q];
                min=max;
                for(int q=0;q<newcol.length;q++)
                if(min>newcol[q])
                min=newcol[q];
for(int q=0;q<newcol.length;q++)
newcol[q]=(newcol[q]-min)/(max-min);
T=(int)Math.sqrt(rowcount-1);
}//normal---------------------------------------------
void display1()
{
for(int q=0;q<newcol.length;q++)
f[q+1][colvar]=Float.toString(newcol[q]);

display();
}//display1()-----------------------------------------
void distance()
{
dist=new double[rowcount-1];
System.out.println("Enter requirement:");
requirement=new float[colcount-2];
req=new String[colcount-2];
for(int q=0;q<req.length;q++)
req[q]=src.nextLine();
for(int q=0;q<req.length;q++)
{
if(req[q].equals("F"))
{req[q]="0";}
if(req[q].equals("M"))
{req[q]="1";}
}
for(int q=0;q<requirement.length;q++)
requirement[q]=Float.parseFloat(req[q]);
requirement[1]=(requirement[1]-min)/(max-min);
float colsum=0.0f;
for(int q=1;q<rowcount;q++)
{
                for(int s=1;s<colcount-1;s++)
                {
                float colminus=requirement[s-1]-Float.parseFloat(f[q][s]);
                float colsqr=colminus*colminus;
                colsum=colsum+colsqr;
                }
dist[q-1]=Math.sqrt(colsum);
//System.out.println(dist[q-1]);
colsum=0.0f;
}
set();
}//distance()-----------------------------
void set()
{
double[] Tset=new double[T];
int[] rowset=new int[T];
for(int q=0;q<Tset.length;q++)
{
Tset[q]=dist[q];
rowset[q]=q;
}
for(int q=T;q<dist.length;q++)
if(dist[q]<largest(Tset))
{
Tset[pos]=dist[q];
rowset[pos]=q;
}
commonclass(rowset);
}//set()--------------------------------------------
double largest(double[] arr)
{
pos=0;
double largest=0.0d;
for(int q=0;q<arr.length;q++)
if(arr[q]>largest)
{
largest=arr[q];
pos=q;
}
return(largest);
}//largest()------------------------------------------
void commonclass(int[] array)
{
String[] commonclass=new String[array.length];
String cl[]={"short","med","tall"};
intclcheck[]=new int[cl.length];
int common=0,clpos=0;
for(int q=0;q<clcheck.length;q++)
clcheck[q]=0;
for(int q=0;q<array.length;q++)
{
for(int s=0;s<colcount;s++)
System.out.print(f[array[q]+1][s]+"\t");
System.out.println();
}
for(int q=0;q<array.length;q++)
commonclass[q]=f[array[q]+1][colcount-1];

for(int q=0;q<commonclass.length;q++)
for(int s=0;s<cl.length;s++)
if(cl[s].equals(commonclass[q]))
clcheck[s]++;
for(int q=0;q<clcheck.length;q++)
if(common<clcheck[q])
{
common=clcheck[q];
clpos=q;
}
System.out.println("Most Common class is "+cl[clpos]);
}//commonclass()------------------------------------------
void read()
{
String file="person.txt";
String line=null;
try
{
BufferedReaderbr=new BufferedReader(new FileReader(file));
while((line=br.readLine())!=null)
rowcount++;
br.close();
br=new BufferedReader(new FileReader(file));
line=br.readLine();
colcount=line.split("\t").length;
br.close();
f=new String[rowcount][colcount];
newcol=new float[rowcount-1];
br=new BufferedReader(new FileReader(file));
int row=0,col=0,lc=0;
while((line=br.readLine())!=null)
{
line=line.replace('F','0');
line=line.replace('M','1');
String[] temp=line.split("\t");
                for(int q=0;q<temp.length;q++)
                f[row][q]=temp[q];
                row++;
}
br.close();
}
catch(FileNotFoundException ex)
{System.out.println("error");}
catch(IOException ex)
{System.out.println("error");}
}
public static void main(String arg[])
{
KNN knn=new KNN();
knn.read();
knn.newcolcal();
knn.normal();
knn.display1();
knn.distance();
}}


more »