more debugs

Wednesday, December 14, 2011

Dynamic Menu In ASP.NET Using MSSQL, and XML

Creating a dynamic menu which gets the menu items and sub menu item during the execution time of the asp.net project requires to construct a table say Menu where we insert the information of the menu items to be rendered in the asp page.


Design Table for Dynamic Menu
Design Table for Dynamic Menu


First drag a menu control from the toolbox of the Visual Studio to the form where you want to see your dynamic menu. Then Create a table having a MenuId as primary key, MenuName where we insert the name of the menu to be displayed in the view page,UnderMenu where we insert sub menu which are to be shown on mouse hover. For example, on the mouse hover of Tutorials Main Menu we need to show different topics such as HTML,Ruby On Rails, C#, ASP.NET, JAVA, MSSQL etc. OR any thing else according to your choice.So now insert the data in the above table according to requirement.

Dynamic Menu
Insert Data Into Table


similarly go on adding menus in parent child relationship.




Here you can see that the parent menu are given under menu id '0' and its child are given its parents menu id as under menu id. Here you can see that MenuId of Company is 2, and its under menu is 0 which indicates that menu Company is parent menu. Then the other two menu Board of Directors and Organization Structure are filled with UnderMenu of 2, Which says that these two menu are child of Company menu.


Now Its time to do some coding to create xml consisting dynamically of all the values in the table given above. The PostUrl field in the above table give the url to follow on click of the menu such the you dont need to hard code Response.Redirect manually to redirect a click to different url.
So now the C# code goes here, Its a bit complicated in viewing but try to understand it.

XmlDataSource xd = new XmlDataSource();
string xmlstr;
xmlstr = "";
xmlstr += "";


Here you will have to make some connections to your database table, open it and call it con.

string sql = "select * from Menu where MenuId order by MenuId";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
string menuName = reader["MenuName"].ToString();
string MenuId = reader["MenuId"].ToString();
string underMenu = reader["UnderMenu"].ToString();

Checks if it is the parent menu. If its parent menu goes to find own child menu in the table

if (underMenu == "0")
{
xmlstr += " ";
string innerSql = "select * from Menu;

make another connection to your database and call it innercon
SqlCommand innerCmd = new SqlCommand(innerSql, innercon);
SqlDataReader innerReader = innerCmd.ExecuteReader();
while (innerReader.Read())
{
string innerMenuName = innerReader["MenuName"].ToString();
string postUrl = innerReader["PostUrl"].ToString();
}
innerReader.Close();
innercon.Close();

Dont forget to close inner connections
}
}
xmlstr += "";
xd.CacheExpirationPolicy = DataSourceCacheExpiry.Absolute;
xd.CacheDuration = 1;
xd.EnableCaching = false;
xd.Data = xmlstr;

MainMenu is the ID of the menu dragged from toolbox to the form in aspx. You can get or change your ID easily from the view.

MainMenu.DataSource = xd;
MainMenu.DataBind();
}
}


Now the only thing left is the DataBinding portion of the program. But if you like to have some designs in your menu you can add which will not affect the entire process how the menu is shown.In aspx page add the databinding functionality.

<asp:Menu ID="MainMenu" Orientation="Horizontal" BackColor="#000000">

<DataBindings> <asp:MenuItemBinding DataMember="TopMenu" TextField="text" ValueField="text" SelectableField="isSelectable" ToolTipField="toolTipMsg" EnabledField="isEnabled" /> <asp:MenuItemBinding DataMember="Menu" TextField="text" ValueField="text" NavigateUrlField="url" SelectableField="isSelectable" ToolTipField="toolTipMsg"/> <asp:MenuItemBinding DataMember="SubMenu" TextField="text" ValueField="text" NavigateUrlField="url" SelectableField="isSelectable" /> </DataBindings> </MainMenu>



The above mentioned MainMenu is ID of the menu dragged and dropped into the aspx page
default color taken by the menu may have been white so try to add colors to the menu styles.Menu Style will be covered later on this blog.



Monday, December 12, 2011

Difference between Store Procedures and Triggers


We can call procedures explicitly but trigger is automatically invoked when the action defined in trigger is performed. Store procedure can't be inactive but triggers can be inactive.


With this short introduction of store procedure and trigger I want to give idea of creating store procedures in any phpmyadmin . It's all same as creating store procedure in MSSQL but the little different part is the delimiter determination. So we have to set delimiter from ';' to '//' which is only one tricky part of store procedure in MySQL.



Sunday, December 11, 2011

Model View Controller Framework

Model View Controller framework(MVC) is a software architecture. The Pattern isolates "domain logic" (the application logic for the user) from the user interface(input and presentation), permitting independent development, testing and maintenance of each(separation of concerns).


MODEL is not necessarily merely a database; the model in MVC is both data and the business/domain.
The model manages the behaviour and data of the application domain, responds to request for information about its state (usually from view) and responds to instruction to change state(usually from the controller).

The CONTROLLER receiver the input and initiates a response by making calls on model objects. A controller accepts input from the user and view part to perform actions based on that input.

The VIEW renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exists for a single model for different purpose. A view part typically has a one to one correspondence with a display surface and known to render to it.

Wednesday, December 7, 2011

Some Definations

What is Serialization?

- The process of  writing the state of an object to a byte system is called serialization, also, it is used to save the program to persistent storage area, like a file and easily restore using deserialization process.

 Why do we need finalize() method when Garbage Collection is there?

-Some time an object (which is lost there object reference) is holding some JAVA resources like file handle, Character font, need to free from the resource before that object is collected by JVM or say garbage collection.

Why finally methods in exceptions?
- The finally method will be executed after a try or catch execution, and mainly used to free up resources. Any code that must be execute before a method returns is put in a finally block.

                               try {
                                     // block of code to monitor for errors
                                    }
                              catch(Exception exObject)
                                             {
                                              // exception handler for Exception Type1
                                              }
                                finally 
                                           {
                                              // block of code to be executed before method returns
                                         }

Method Overloading ?
   -   Operator Overloading is a specific case of polymorphism in which some or all of opertors like    +,=,or == have different implementations depending on the types of their arguments.

        Function Overloading or method overloading allows to creation of several methods with the same name which differ from each other in terms of the type of input and the type of the output of the function(not available in JAVA).

Method overloading is usually associated with statically-typed programming languages which enforce type checking in functions call.


Method Overriding ?
   - In overriding, a method in a super class is overridden the subclass. The method in the subclass will have the same signature as that of the super class, Since the method in the subclass has the same signature and name as the method of its superclass, it is termed as overriding.
                         


Monday, December 5, 2011

Telnet - SMTP Commands (sending mail using telnet)

Telnet - SMTP Commands (sending mail using telnet)

In order to access your mailbox you will need three things.

1. An active internet connection.

2. The address of a mail server capable of relaying for you - usually
provided by your internet provider.(e.g. mail.domain.ext)

3. A valid email address(e.g. mail@domain.ext)

After verification of the above mentioned three points go to following steps.

1. The first thing is to do is open a connection from your computer
to your mail server.

telnet mail.domain.ext 25

you should receive a reply like:

Trying ???.???.???.???...
Connected to mail.domain.ext.
Escape character is '^]'.
220 mail.domain.ext ESMTP Sendmail ?version-number?; ?date+time+gmtoffset?

2. You will then need to delcare where you are sending the email from:

HELO

- dont worry too much about your local domain name although you
really should use your exact fully qualified domain name as seen by
the outside world the mail server has no choice but to take your
word for it as of RFC822-RFC1123.
This should give you:

250 mail.domain.ext Hello [loc.al.i.p], pleased
to meet you

3. Now give your email address:

(On many mailservers the space after the : is
required rather that optional.)

MAIL FROM: mail@domain.ext
Should yeild:
250 2.1.0 mail@domain.ext... Sender ok

4. If it doesn't please see possible problems.

5. Now give the recipients address:

RCPT TO: mail@otherdomain.ext
Should yeild:
250 2.1.0 mail@otherdomain.ext... Recipient ok
6. If it doesn't please see possible problems. Note Google mail
servers require < and > around the email address.

7. To start composing the message issue the command DATA

8. If you want a subject for your email type Subject:-type subject
here- then press enter twice (these are needed to conform to RFC 882)

9. You may now proceed to type the body of your message (e.g. hello
mail@otherdomain.ext from mail@domain.ext)

10. To tell the mail server that you have completed the message enter
a single "." on a line on it's own.

The mail server should reply with: 250 2.0.0 ???????? Message
accepted for delivery

11. You can close the connection by issuing the QUIT command.

The mailserver should reply with something like:221 2.0.0
mail.domain.ext closing connection
Connection closed by foreign host.

Wednesday, November 30, 2011

Database Management System

Normalization is the process of organizing data in a database. This includes creating tables and
establishing relationships between those tables according to rules designed both to protect the
data and to make the database more flexible by eliminating two factors: redundancy and
inconsistent dependency.
Redundant data wastes disk space and creates maintenance problems. If data that exists in more
than one place must be changed, the data must be changed in exactly the same way in all
locations. A change in the customer is much easier to implement if that data is stored only in the
Customers table and nowhere else in the database.
What is an "inconsistent dependency"? While it is intuitive for a user to look in the Customers table
for the address of a particular customer, it may not make sense to look there for the salary of the
employee who calls on that customer. The employee's salary is related to, or dependent on, the
employee and thus should be moved to the Employees table. Inconsistent dependencies can
make data difficult to access; the path to find the data may be missing or broken.

Goals
  
  • Ensuring data dependencies make sense. 
  • Role of Normalization.

Role of Normalization

In the E-R model, a conceptual schema using an entity- relationship diagram is built and then
mapped to a set of relations. This technique ensures that each entity has information about only
one thing and once the conceptual schema is mapped into a set of relations, each relation would
have information about only one thing. The relations thus obtained would normally not suffer from
any of the anomalies. This bottom-up approach is likely to lead to a relation that is likely to suffer
from all the problemsn. For example, the relation is highly likely to have redundant information and
update, deletion and insertion anomalies. Normalization of such large relation will then be essential
to avoid (or at least minimize) these problems.
Now to define the normal forms more formally, we first need to define the concept of functional
dependence.

Functional Dependency

Consider a relation R that has two attributes A and B. The attribute B of the relation is functionally
dependent on the attribute A if and only if for each value of A no more than one value of B is
associated. In other words, the value of attribute A uniquely determines the value of B and if there
were several tuples that had the same value of A then all these tuples will have an identical value
of attribute B.
If B is functionally dependent on A (or A functionally determines B).

For example, in the student database that we have discussed earlier, we have the following
functional dependencies:
sno -> sname
sno -> address
cno -> cname
cno -> instructor
instructor -> office

These functional dependencies imply that there can be only one name for each sno, only one
address for each student and only one subject name for each cno. It is of course possible that
several students may have the same name and several students may live at the same address. If
we consider cno -> instructor, the dependency implies that no subject can have more than one
instructor (perhaps this is not a very realistic assumption). Functional dependencies therefore
place constraints on what information the database may store. In the above example, one may be
wondering if the following FDs hold
sname -> sno
cname -> cno

First Normal Form (1NF)

A table satisfying the properties of a relation is said to be in first normal form. As discussed in an
earlier chapter, a relation cannot have multivalued or composite attributes. This is what the 1NF
requires.
A relation is in 1NF if and only if all underlying domains contain atomic values only.
The first normal form deals only with the basic structure of the relation and does not resolve the
problems of redundant information or the anomalies discussed earlier. All relations discussed in
these notes are in 1NF.
For example consider the following example relation:
student (sno, sname, dob)
Add some other attributes so it has anomalies and is not in 2NF

The attribute dob is the date of birth and the primary key of the relation is sno with the functional
dependencies sno -> sname and sno -> dob. The relation is in 1NF as long as dob is considered
an atomic value and not consisting of three components (day, month, year). The above relation of
course suffers from all the anomalies that we have discussed earlier and needs to be normalized.
(add example with date of birth)


Second Normal Form (2NF)

The second normal form attempts to deal with the problems that are identified with the relation
above that is in 1NF. The aim of second normal form is to ensure that all information in one
relation is only about one thing.
A relation is in 2NF if it is in 1NF and every non-key attribute is fully dependent on each candidate
key of the relation.
To understand the above definition of 2NF we need to define the concept of key attributes. Each
attribute of a relation that participates in at least one candidate key of is a key attribute of the
relation. All other attributes are called non-key.
The concept of 2NF requires that all attributes that are not part of a candidate key be fully
dependent on each candidate key. If we consider the relation
student (sno, sname, cno, cname)
and the functional dependencies
sno -> cname
cno -> cname

and assume that (sno, cno) is the only candidate key (and therefore the primary key), the relation
is not in 2NF since sname and cname are not fully dependent on the key. The above relation
suffers from the same anomalies and repetition of information as discussed above since sname
and cname will be repeated. To resolve these difficulties we could remove those attributes from
the relation that are not fully dependent on the candidate keys of the relations. Therefore we
decompose the relation into the following projections of the original relation:
S1 (sno, sname)
S2 (cno, cname)
SC (sno, cno)
Use an example that leaves one relation in 2NF but not in 3NF.
We may recover the original relation by taking the natural join of the three relations.
If however we assume that sname and cname are unique and therefore we have the following
candidate keys
(sno, cno)
(sno, cname)
(sname, cno)
(sname, cname)
The above relation is now in 2NF since the relation has no non-key attributes. The relation still has
the same problems as before but it then does satisfy the requirements of 2NF. Higher level
normalization is needed to resolve such problems with relations that are in 2NF and further
normalization will result in decomposition of such relations.

Third Normal Form (3NF)

Although transforming a relation that is not in 2NF into a number of relations that are in 2NF
removes many of the anomalies that appear in the relation that was not in 2NF, not all anomalies
are removed and further normalization is sometime needed to ensure further removal of
anomalies. These anomalies arise because a 2NF relation may have attributes that are not directly
related to the thing that is being described by the candidate keys of the relation. Let us first define
the 3NF.
A relation R is in third normal form if it is in 2NF and every non-key attribute of R is non-transitively
dependent on each candidate key of R.
To understand the third normal form, we need to define transitive dependence which is based on
one of Armstrong's axioms. Let A, B and C be three attributes of a relation R such that A -> B and
B -> C. From these FDs, we may derive A -> C. As noted earlier, this dependence A -> C is
transitive.
The 3NF differs from the 2NF in that all non-key attributes in 3NF are required to be directly
dependent on each candidate key of the relation. The 3NF therefore insists, in the words of Kent
(1983) that all facts in the relation are about the key (or the thing that the key identifies), the whole
key and nothing but the key. If some attributes are dependent on the keys transitively then that is
an indication that those attributes provide information not about the key but about a kno-key
attribute. So the information is not directly about the key, although it obviously is related to the key.
Consider the following relation
subject (cno, cname, instructor, office)
Assume that cname is not unique and therefore cno is the only candidate key. The following
functional dependencies exist
sno -> cname
cno -> instructor
instructor -> office
We can derive cno -> office from the above functional dependencies and therefore the above
relation is in 2NF. The relation is however not in 3NF since office is not directly dependent on cno.
This transitive dependence is an indication that the relation has information about more than one
thing (viz. course and instructor) and should therefore be decomposed. The primary difficulty with
the above relation is that an instructor might be responsible for several subjects and therefore his
office address may need to be repeated many times. This leads to all the problems that we
identified at the beginning of this chapter. To overcome these difficulties we need to decompose
the above relation in the following two relations:
s (cno, cname, instructor)
ins (instructor, office)
s is now in 3NF and so is ins.
An alternate decomposition of the relation subject is possible:










Tuesday, November 29, 2011

jQuery

Image SlideShow Using jQuery

index.html

<!doctype html>
<html>
    <head>
        <link rel="stylesheet" href="css/style.css">
        <title>Image SlideShow</title>       
    </head>
   
    <body>
        <header id="main-header">
        </header>

        <section id="slideshow-app">       
            <div id="slideshow-frame">
                <ul id="slideshow-nav"></ul>               
                <ul id="slideshow-images">
                    <li class = "visible">
                        <figure class="slideshow-image">
                            <img alt="" src="images/everest.jpg" />
                            <figcaption>Everest Nepal</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                            <img alt="" src="images/mountain-lake.jpg" />
                            <figcaption>Mountain Lake</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                            <img alt="" src="images/kantegapeak.jpg" />
                            <figcaption>Kantega Peak</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                            <img alt="" src="images/khumbu_valley.jpg" />
                            <figcaption>Khumbu Valley</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                        <img alt="" src="images/mount everest.jpg" />
                        <figcaption>Mount Everest</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                        <img alt="" src="images/mt_everest.jpg" />
                        <figcaption>Sagarmatha</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                        <img alt="" src="images/view-at-chomrong.jpg" />
                        <figcaption>View at Chomrong</figcaption>
                        </figure>
                    </li>
                </ul>
            </div>
            <div id="slide-control">
                <a id="previous-slide" href="#">&larr;</a>
                <a id="play-toggle" href="">Pause</a>
                <a id="next-slide" href="">&rarr;</a>
            </div>
        </section>
               
        <footer>
            <script src="js/jquery-1.5.1.js"></script>
            <script src="js/application.js"></script>   
        </footer>
    </body>
</html>




application.js



function slide_next() {
    $("#slideshow-nav li#"+ page).removeClass("current-slide");
    if (page >= total_images)
        page= 1;
    else
        page++;
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    $("#pagination").text(page);
    var current = $('#slideshow-images li.visible');
    current.removeClass('visible');
    current.fadeOut(100);   
    var remaining_images = current.nextAll().length;       
    if (remaining_images == 0) {
        $('#slideshow-images li:first').addClass('visible');
        $('#slideshow-images li:first').fadeIn('slow');
    }
    else {
        current.next().fadeIn("slow");
        current.next().addClass('visible');
    }
}

function slide_jump(img_number) {
    $("#slideshow-nav li#"+ page).removeClass("current-slide");
    var current = $('#slideshow-images li.visible');
    current.removeClass('visible');
    current.fadeOut(100);
    page=img_number;
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    var first_image = $('#slideshow-images li:first');
    for(i=1;i<page;i++)
    {
        first_image = first_image.next();
    }
    first_image.addClass('visible');
    first_image.fadeIn('slow');
}

function slide_previous() {
    $("#slideshow-nav li#"+ page).removeClass("current-slide");
    if (page <= 1)
        page= total_images;
    else
        page--;
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    $("#pagination").text(page);
    var current = $('#slideshow-images li.visible');
    current.removeClass('visible');
    current.fadeOut(100);
    var remaining_images = current.prevAll().length;
    if (remaining_images == 0) {
        $('#slideshow-images li:last').addClass('visible');
        $('#slideshow-images li:last').fadeIn('slow');
    }
    else {
        current.prev().addClass('visible');
        current.prev().fadeIn('slow');
    }
}

function auto_play() {
    if (play == true)
        slide_next();
}

function play_toggle() {
        if ($("#play-toggle").text()=="Pause") {
            play=false;
            $("#play-toggle").text("Play");
        }
        else {
            play=true;
            $("#play-toggle").text("Pause");
        }
}

$(function () {
    play = true;
    page=1;
    $("#pagination").text(page);
   
    total_images= $('#slideshow-images li.visible').nextAll().length +1;
    for(i=1;i<=total_images;i++) {       
        $('#slideshow-nav').append("<li>.</li>");
        $('#slideshow-nav li:last').attr("id",i);
    }
   
    $("#slideshow-nav li").click(function () {
        slide_jump(this.id);
    });
   
    $('#slideshow-images li:first').fadeIn("slow");
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    //automatic slide show
    setInterval("auto_play()",1500);
   
    $('#next-slide').click( function () {
        slide_next();
        return false;
    });

    $('#play-toggle').click( function () {
        play_toggle();
        return false;
    });
   
    $("#slideshow-frame, #slide-control").mouseover(function () {
        play=false;
    });
   
    $("#slideshow-frame, #slide-control").mouseout(function() {
        if ($("#play-toggle").text()=="Pause")
            play=true;
    });

    $('#previous-slide').click( function () {
        slide_previous();
        return false;
    });
});

style.css

body {
    text-align: center;
}

#slideshow-app {
    background: #000000;
    padding: 8px 0px 10px 0px;
}

#slideshow-frame {
    border: solid 1px #D4CDCF;
    height: 620px;
    width: 660px;
    display:inline-block;
    border-radius: 20px;
    padding-top: 0px;
    background: #000000;
    overflow: hidden;
    margin-bottom: 10px;
    padding-right: 30px;
}

#pagination {
    color: #D4CDCF;
}

ul#slideshow-nav {
    cursor: hand;
}

ul#slideshow-nav li{
    display:inline;
    color: #73172E;
    font-size: 30px;
    font-weight: bolder;
    padding-right: 15px;
}

ul#slideshow-nav li.current-slide {
    color: #D4CDCF;
}

ul#slideshow-images {
    list-style: none;
    overflow:hidden;
}

ul#slideshow-images li {
    display: none;
    overflow: hidden;
}

ul#slideshow-images li img {
    -webkit-box-reflect: below 5px -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(.8, transparent), to(white));
    -webkit-border-radius: 7px;
    margin-bottom: 100px;
    height: 400px;
    width: 533px;
}

figure.slideshow-image figcaption {
    color: #D4CDCF;
}

figcaption {
    display:block;
}

#slide-control a {
    text-decoration: none;
    font-size: 30px;
    padding: 0px 18px;
    background-color: #000000; /* fallback color */
    background: -moz-linear-gradient(100% 100% 90deg, #303030, #000000);
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#505050), to(#000000));
    color: #FFFFFF;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    box-shadow: 0 5px 5px rgba(0,0,0,.4);
    text-shadow: 0 3px 3px rgba(255,255,255,.6);
}

#slide-control a:hover {
    background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#666666), to(#666666), color-stop(.6,#333));
    background-color: #000000;
}











Computer Networks


Network Architecture (model)


1. Peer-to-peer architecture

  Often referred to simply as peer-to-peer, or abbreviated P2P, peer-to-peer architecture is a type of network in which each workstation has equivalent capabilities and responsibilities. This differs from client/server architectures where some computers are dedicated to serving the others. Peer-to-peer networks are generally simpler but they usually do not offer the same performance under heavy loads. The P2P network itself relies on computing power at the ends of a connection rather than from within the network itself.
P2P computing takes advantage of existing computing power, computer storage and networking connectivity, allowing users to leverage their collective power to the ‘benefit’ of all.

All nodes are both clients and servers. Each node provides and consumes data and any one node can initiate a connection.

   i. How Peer-to-peer File-sharing Clients Work

Once you have downloaded and installed a P2P client, if you are connected to the Internet you can launch the utility and you are then logged into a central indexing server. This central server indexes all users who are currently online connected to the server. This server does not host any files for downloading. The P2P client will contain an area where you can search for a specific file. The utility queries the index server to find other connected users with the file you are looking for. When a match is found the central server will tell you where to find the requested file. You can then choose a result from the search query and your utility when then attempt to establish a connection with the computer hosting the file you have requested. If a successful connection is made, you will begin downloading the file. Once the file download is complete the connection will be broken.
A second model of P2P clients works in the same way but without a central indexing server.  In this scenario the P2P software simply seeks out other Internet users using the same program and informs them of your presence online, building a large network of computers as more users install and use the software.

  ii. P2P Security Concerns

      One major concern of using P2P architecture in the workplace is, of course, network security. Security concerns stem from the architecture itself. Today we find most blocking and routing handles by a specific server within network, but the P2P architecture has no single fixed server responsible for routing and requests. The first step in securing your P2P network is to adopt a strict usage policy within the workplace. In securing your network against attacks and viruses there are two main strategies where focus is on controlling the network access or the focus is put on controlling the files. A protocol-based approach is where system administrators use a software or hardware solution to watch for and block intrusive network traffic being received through the P2P clients. A second method of protection is a software solution which would provide file surveillance to actively search for files based on their type, their name, their signature or even their content.

iii. P2P at Work

         P2P is not only popular with home users but many small businesses have come to rely on this cost-effective solution for sharing files with co-workers and clients. P2P promotes the ease of working together when you're not physically located in the same office. In just seconds updated files and data can be shared with peers and confidential files can be blocked for security. Additionally, companies can also block access to Internet music and video files to assist in maintaining a work-oriented P2P network. Not only does this keep the company free and clear from legal issues regarding music downloading and sharing but it also keeps the corporate bandwidth usage down.

iv.  P2P Characteristics:
¨                    1. Clients are also servers and routers: nodes contribute content, storage, memory and CPU. 
2
¨                    2. Nodes are autonomous (no administrative authority)
3
¨                  3. Network is dynamic (nodes enter and leave the network frequently)

¨                  4. Nodes collaborate directly with each other with having widely varying capabilities

v. Benefit:

¨             Efficient use of resources: Unused bandwidth, storage, processing power at the edge of the network
¨                                   -  Scalability: consumers of resource also donate resources
¨                                  -   Reliability: no single point of failure
¨                                  -   Ease of administration: built in fault tolerant, replication and load balancing. Nodes self organize.


Applications:
¨      File sharing (Gnutella, kazaa)
¨      Multilayer games.
¨      Collaborative applications
¨      Distributed computation
¨      Ad-hoc network.


Gnutella (example software)

Client/Server Architecture
Client server is a network architecture which separates the client from the server. Each client software can sends request to a server. There are many different types of server like file server, web server, mail server etc..
CSArchitecture
Properties:
Server
Client
¨      Passive (slave)
¨      Waiting for requests
¨      On request serves them and reply
¨      Active (master)
¨      Sends request
¨      Wait until reply arrives
Types of client:
Thin client: a personal computer that does not have to be very powerful because it only presents the users interface to the user. Largely used for interaction with processing layer.
Thick client: a typically powerful personal computer capable of handling independent application processes like notebook computer or PC.
Types of server: database server, transaction server (OLTP), OLAP server, Application server, messaging (email, news), web server etc.
Tired architecture: Generic client server architecture has two types of nodes on the network: client and server.
Three tired architecture: 1. Client tier (web browser).2 application server tier which process data for the clients: a server computer dedicated to running certain software applications (file, print server). 3 database server tier which store data for the application servers: computer program that provide database services to other computer programs. Client tier never communicate with data tier in three tier architecture.    
Wireless LAN:
A wireless LAN or WLAN is a wireless local area network, which is the linking of two or more computers without using wires. WLAN utilizes spread-spectrum or OFDM modulation technology based on radio waves to enable communication between devices in a limited area, also known as the basic service set.
Architecture:
All components that can connect into a wireless medium in a network are referred to as stations. All stations are equipped with wireless network interface cards (WNICs). Wireless stations fall into one of two categories: access points and clients.
  • Access points
Access points (APs) are base stations for the wireless network. They transmit and receive radio frequencies for wireless enabled devices to communicate with.
  • Clients
Wireless clients can be mobile devices such as laptops, personal digital assistants, IP phones, or fixed devices such as desktops and workstations that are equipped with a wireless network interface.
Basic service set
The basic service set (BSS) is a set of all stations that can communicate with each other. There are two types of BSS: independent BSS and infrastructure BSS. Every BSS has an identification (ID) called the BSSID, which is the MAC address of the access point servicing the BSS.
  • Independent basic service set
An independent BSS is an ad-hoc network that contains no access points, which means they can not connect to any other basic service set.
  • Infrastructure basic service set
An infrastructure BSS can communicate with other stations not in the same basic service set by communicating through access points.

Extended service set

An extended service set (ESS) is a set of connected BSSes. Access points in an ESS are connected by a distribution system. Each ESS has an ID called the SSID which is a 32-byte (maximum) character string. For example, "linksys" is the default SSID for Linksys routers.

Types of wireless LANs

Peer-to-peer

Peer-to-Peer or ad-hoc wireless LAN
A peer-to-peer (P2P) allows wireless devices to directly communicate with each other. Wireless devices within range of each other can discover and communicate directly without involving central access points. This method is typically used by two computers so that they can connect to each other to form a network.
If a signal strength meter is used in this situation, it may not read the strength accurately and can be misleading, because it registers the strength of the strongest signal, which may be the closest computer.

Bridge

A bridge can be used to connect networks, typically of different types. A wireless Ethernet bridge allows the connection of devices on a wired Ethernet network to a wireless network. The bridge acts as the connection point to the Wireless LAN.
The benefits of wireless LANs include:
  • Convenience: The wireless nature of such networks allows users to access network resources from nearly any convenient location within their primary networking environment (home or office). With the increasing saturation of laptop-style computers, this is particularly relevant.
  • Mobility: With the emergence of public wireless networks, users can access the internet even outside their normal work environment. Most chain coffee shops, for example, offer their customers a wireless connection to the internet at little or no cost.
  • Productivity: Users connected to a wireless network can maintain a nearly constant affiliation with their desired network as they move from place to place. For a business, this implies that an employee can potentially be more productive as his or her work can be accomplished from any convenient location.
  • Deployment: Initial setup of an infrastructure-based wireless network requires little more than a single access point. Wired networks, on the other hand, have the additional cost and complexity of actual physical cables being run to numerous locations (which can even be impossible for hard-to-reach locations within a building).
  • Expandability: Wireless networks can serve a suddenly-increased number of clients with the existing equipment. In a wired network, additional clients would require additional wiring.
  • Cost: Wireless networking hardware is at worst a modest increase from wired counterparts. This potentially increased cost is almost always more than outweighed by the savings in cost and labor associated to running physical cables
Disadvantage:
  • Security: Wireless LAN transceivers are designed to serve computers throughout a structure with uninterrupted service using radio frequencies. Because of space and cost, the antennas typically present on wireless networking cards in the end computers are generally relatively poor. In order to properly receive signals using such limited antennas throughout even a modest area, the wireless LAN transceiver utilizes a fairly considerable amount of power. What this means is that not only can the wireless packets be intercepted by a nearby adversary's poorly-equipped computer, but more importantly, a user willing to spend a small amount of money on a good quality antenna can pick up packets at a remarkable distance; perhaps hundreds of times the radius as the typical user. In fact, there are even computer users dedicated to locating and sometimes even cracking into wireless networks, known as wardrivers. On a wired network, any adversary would first have to overcome the physical limitation of tapping into the actual wires, but this is not an issue with wireless packets. To combat this consideration, wireless networks users usually choose to utilize various encryption technologies available such as Wi-Fi Protected Access (WPA). Some of the older encryption methods, such as WEP are known to have weaknesses that a dedicated adversary can compromise.
  • Range: The typical range of a common 802.11g network with standard equipment is on the order of tens of meters. While sufficient for a typical home, it will be insufficient in a larger structure. To obtain additional range, repeaters or additional access points will have to be purchased. Costs for these items can add up quickly.
  • Reliability: Like any radio frequency transmission, wireless networking signals are subject to a wide variety of interference, as well as complex propagation effects (such as multipath, or especially in this case Rician fading) that are beyond the control of the network administrator.
  • Speed: The speed on most wireless networks (typically 1-108 Mbit/s) is reasonably slow compared to the slowest common wired networks (100 Mbit/s up to several Gbit/s). There are also performance issues caused by TCP and its built-in congestion avoidance.
Wireless LANs present a host of issues for network managers. Unauthorized access points, broadcasted SSIDs, unknown stations, and spoofed MAC addresses are just a few of the problems addressed in WLAN troubleshooting. Most network analysis vendors, such as Network Instruments, Network General, and Fluke, offer WLAN troubleshooting tools or functionalities as part of their product line.