Sunday, November 2, 2008

sample sequence







Initial Sequence Number


Number of Seconds

Number of Connections

Number of FIN

Number of SYN

Number of SYN/ACK

Number of FIN/ACK



Answer



Thursday, September 18, 2008

Simplest Anagram Finder.

It finds the anagram of a word from a set of pre processed words....



#include
#include
#include

class finder
{
private:
char words[1300][10],input[30][10],output[110];
int fileCounter,flag;
long unsigned int wordPro[1300],outputProduct[10];
int letterCounter,inputCounter,outputCounter,prime;
char c;
FILE *dictonary;
public:
finder()
{
prime=37;
fileCounter=letterCounter=flag=inputCounter=outputCounter=0;
for (int i=0;i<1300;i++)
wordPro[i]=37;//assign it to any prime coz the product
//of any set of numbers is always
//unique.
for(int i=0;i<10;i++)
outputProduct[i]=37;

}
void fillArray();
void getInput();
void getProduct();
void getOutputWithPrime();
};


int main() {
finder f1;
f1.fillArray();
f1.getProduct();
f1.getInput();
f1.getOutputWithPrime();
return 0;
}

void finder::fillArray()
{
dictonary = fopen("dump1","r");//file which stores the words..
//each word in a new line
do {
c = fgetc (dictonary);
if ((c>=48 && c<=59)||(c>=97 && c<=122)||c==41)//characters that I wanted
//to read-in case
//the list contained some unwanted characters.
{
words[fileCounter][letterCounter++]=c;
flag=0;
}
if((c==10||c==13)&&flag==0)
{
words[fileCounter++][letterCounter]='\0';
letterCounter=0;
flag=1;
}
} while (c != EOF);
fclose(dictonary);
}

void finder::getOutputWithPrime()
{
for (int i=0;i {
for (int j=0;j {if(outputProduct[i]!=wordPro[j])
continue;
else
{ printf("%s,",words[j]);
strcpy(output,words[j]);strcpy(output,",");goto level1;
}
}
level1:;
}
printf("\n");
}
void finder::getProduct()
{
for(int i=0;i {
for (int j=0;j wordPro[i]*=(int)(words[i][j]);
}
}


void finder::getInput()
{
char temp[30];
scanf("%s",temp);
while(strcmp(temp,"end")!=0)
{
if(!strcmp(temp,"#")==0)
{
strcpy(input[inputCounter],temp);
for (int i=0;i outputProduct[inputCounter]*=(int)temp[i];
inputCounter++;
}
scanf("%s",temp);
}
}


Tuesday, August 5, 2008

A Simple TCP program for Beginners

This is a simple TCP program in which the server sends the data and the client receives it and keeps on displaying it untill the server sends a value -1. This code is too simple to explain.

MyServer.java


import java.net.*;
import java.io.*;
public class MyServer
{
public static void main(String xx[]) throws IOException
{
ServerSocket ss=new ServerSocket(5439);
Socket s=ss.accept();
byte arr[]=new byte[256];
String str=new String();
str="welcome";
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(read);
while(!str.equals("-1"))
{
str=br.readLine();
arr=str.getBytes();
OutputStream out=s.getOutputStream();
out.write(arr);
}
ss.close();
}
}






MyClient.java


import java.net.*;
import java.io.*;
public class MyClient
{
public static void main(String xx[]) throws IOException
{
Socket client=new Socket(InetAddress.getLocalHost(),5439);
byte bb[]=new byte[256];
InputStream in=client.getInputStream();
in.read(bb);
String obj=new String(bb);
while(!obj.equals("-1"))
{
System.out.println(obj);
bb=new byte[256];
in.read(bb);
obj=new String(bb);
}
client.close();

}
}

Thursday, July 31, 2008

Java Database codes-for beginners

Steps for connecting and accessing Databases using Java-For Beginners

1> Establishing Connection

1> Load drivers
class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

2> Make Connection
Connection con=DriverManager.getConnection("dataSourceName","userName","password");

3> Creating JDBC statement
Statement stmt=con.createStatement();

4> For creation, Updation, Insertion, Deletion
stmt.executeUpdate(string query);

5> For Retieving values from the database
ResultSet rs=stmt.executeQuery(String query);
while(rs.next())
{
String str=rs.getString(fieldName);
Float fl=rs.getFloat(fieldName);
}
6> Closing the Connection
stmt.close();
con.close();



Note:-
1> before this database needs to be created.
2> data source name also needs to be created
http://support.microsoft.com/kb/305599
(for creating data source name.)

Tuesday, July 29, 2008

Simplest UDP Program in Java for Beginners

The simplest program to show the data transfer among the client and server using Universal Datagram Protocol can be written as...


myServer.java

import java.io.*;
import java.net.*;

class myServer
{

public static void main(String []arg)throws IOException
{
int serverPort=5239;
int clientPort=5240;
int bufferSize=1024;
String data="Hello Client";
byte buffer[]= new buffer[buffersize];
DatagramSocket ds;
DatagramPacket dp;

buffer=data.getBytes();
ds=new DatagramSocket(serverPort);
dp=new DatagramPacket(buffer,buffer.length,InetAddress.getLocalHost(),clientPort);
ds.send(dp);
ds.close();
}





myClient.java

import java.io.*;
import java.net.*;

class myClient
{

public static void main(String []arg)throws IOException
{
int serverPort=5239;
int clientPort=5240;
int bufferSize=1024;
byte buffer[]= new buffer[buffersize];
DatagramSocket ds;
DatagramPacket dp;

ds=new DatagramSocket(clientPort);
dp=new DatagramPacket(buffer,buffer.length);
ds.recieve(dp);
System.out.println(new String(dp.getData()));
ds.close();
}


}

Explanation

We can see that there are two classes used.
DatagramSocket
DatagramPacket


DatagramSocket is used to open a socket and send or recieve packets, the reciever's port number is passed as the parameter.


DatagramPacket class has two constructors.

one for sending packets constructed as
new DatagramPacket(byte []buffer,bufferSize,Address,recieverPort)

second one is for recieving packets which is constructed as
new DatagramPacket(byte []buffer,bufferLength)



Note:- It is very important to close what you open, so always have an habit of closing every thing you open