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();

}
}