Pages

Showing posts with label Computer Networking. Show all posts
Showing posts with label Computer Networking. Show all posts

Friday, January 18, 2013

Prime/Even/Odd number sample programs using VB.NET


Prime number sample program using vb.net.

Public Sub PrintPrimeNumber()
        Dim Num As Long
        Dim NN As Long
        Dim IsPrime As Boolean

        For Num = 2 To 100
            IsPrime = True
            For NN = 2 To Int(Num / 2)
                If Num Mod NN = 0 Then
                    IsPrime = False
                    Exit For
                End If
            Next
            If IsPrime Then
                Response.Write(Num & " is a prime number!" & "<br>")
            End If
        Next
    End Sub

Odd number sample program using vb.net


Public Sub PrintOddNumber()
        For number As Integer = 0 To 100
            If (number Mod 2) = 1 Then
                Response.Write(number & ",  ")
            End If
        Next
    End Sub

Even number sample program using vb.net

    Public Sub PrintEvenNumber()
        For number As Integer = 0 To 100
            If (number Mod 2) = 0 Then
                Response.Write(number & ",  ")
            End If
        Next
    End Sub

Friday, December 14, 2012

redirect your site to a mobile version through JavaScript


Here JavaScript comes to the rescue and I wrote a script that makes the redirection happen called “redirection_mobile.js“.

You can find the source here on Github.

The first thing to keep in mind is that the function implemented checks the User-Agent string from the Navigator object and from there it decides if the redirection needs to happen

In some cases the user wants to access to the Desktop version of the site from a mobile device (sometimes the desktop version has more functionality). The script handles this situation as well, it checks if the previous page hit was one from the mobile site (we can suppose the user clicked on a link such “Go to full site“) or if there is a specific parameter in the querystring of the URL. In those cases the redirection won’t occur. To keep the user in the desktop version for the whole session,
sessionStorage object has been used, specifically an item will be stored to distinguish if we’re browsing through the desktop site.

There is a fallback for old browsers that don’t support sessionStorage, and a cookie will be used. The cookie that makes the access to the desktop version from a mobile device possible will expiry in one hour or you configure the expiry time.

iPhone, iPad, iPod, Android phones support completely sessionStorage, there are still some versions of Blackberry that using IE don’t and so we still need the “cookie” fallback.

The function accepts an argument which is a configuration object with few properties:
- mobile_prefix : prefix appended to the hostname, such as “m” to redirect to “m.domain.com”. “m” is the default value if the property is not specified.

- mobile_url : mobile url to use for the redirection (without the protocol), such as “whatever.com”/example to redirect to “whatever.com/example”. If “mobile_prefix” is existing as well, “mobile_prefix” will be ignored. Empty string is the default value.

- mobile_scheme : url scheme (http/https) of the mobile site domain, such as “https” to redirect to “https://m.domain.com&#8221;. The protocol of the current page is the default value.

- noredirection_param – up to version 0.6 param was used: parameter to pass in the querystring of the URL to avoid the redirection (the value must be equal to “true”). Default value is “noredirection”. Eg: http://domain.com?noredirection=true. It’s also the name of the item in the localStorage (or cookie name) used to avoid mobile redirection. Prior version 0.9.5 this parameter was called “redirection_paramName”, but I renamed it to make the meaning clearer.

- cookie_hours : number of hours the cookie needs to exist after redirection to desktop site. “1″ is the default value.

- tablet_redirection : boolean value that enables/disables(default) the redirection for tablet such as iPad, Samsung Galaxy Tab, Kindle or Motorola Xoom. – Default:false. The value needs to be a string (so wrapped in double or single quotes). If ‘tablet_url’ parameter not specified, the user will be redirected to the same URL as for mobile devices.
- tablet_url : url to use for the redirection in case the user is using a tablet to access the site. Default value is “”
- keep_path : boolean to determine if the destination url needs to keep the path from the original url. Default value is ‘false’
- keep_query : boolean to determine if the destination url needs to keep the querystring from the original url. Default value is ‘false’
- beforeredirection_callback : if specified, callback launched before the redirection happens. If a falsy value is returned from the callback the redirection doesn’t happen.

To use “redirection_mobile” function, you need to load your script in the HTML of the “desktop” pages and call it as SA.redirection_mobile(config). See the code below:

<!doctype html>
<html>
    <head>
        <title></title>
        <script type="text/javascript" src="/js/redirection_mobile.min.js"/>
        <script type="text/javascript">
            SA.redirection_mobile ({noredirection_param:"noredirection", mobile_prefix : "mobile", cookie_hours : "2" });
        </script>


For instance, in this case, accessing from a mobile device to http://www.domain.com, you’ll be redirected to “http://mobile.domain.com“.

Considering the previous code, from version 0.6, if you hit a page such as “http://domain.com/?noredirection=true” the redirection won’t happen. For all the browser session, if sessionStorage is supported by the browser, the redirection won’t occur. If sessionStorage (HTML5) is not supported, a cookie “noredirection=true” will be stored for 2 hours and it will block the redirection to the mobile site.

If sessionStorage (HTML5) is not supported, a cookie named “noredirection” will be stored for 2 hours and it will block the redirection to the mobile site.

The script from version 0.5 allows you to redirect the user to whatever url. Thus if you need to redirect the user to “https://domain2.com/mobile” now you can invoke the function like this:


    <script type="text/javascript">
        SA.redirection_mobile ({mobile_scheme:"https", mobile_url : "domain2.com/mobile"});
    </script>

Alternatively you can use “redirection_mobile_self.js”, that is it’s an anonyimous self-executing function and it uses it uses the default values for the different properties:
- “mobile_prefix” : “m”
- “redirection_paramName” : “mobile_redirect”
- “cookie_hours” : 1
- “mobile_url” : “”
- “mobile_scheme” : protocol of the current page
- “tablet_redirection” : false
- “beforeredirection_callback” : n/a

It doesn’t need any configuration or any invocation, so you just need to drop it on your webserver and call the script from the HTML of the “desktop” pages . See code below:

<!doctype html>
<html>
    <head>
        <title></title>
        <script type="text/javascript" src="/js/redirection_mobile_self.min.js"/>

in this case, accessing from a mobile device to http://www.domain.com, you’ll be redirected to “http://m.domain.com“.

To redirect to a desktop/standard version of the site from a mobile device, you may need to embed a link in your mobile pages such as

<a href="http://www.domain.com">Go to main site</a>

and the script included in the desktop page will do the rest.

I also created “redirection_mobile_testable.js” that is just a copy from “redirection_mobile.js”, but it’s using few arguments such as “document”, “window”, “navigator” for testing purpose. Test cases have been written, using QUnit, to test this script and they mock “document”, “window” and “navigator” in a rudimentary way.

The scripts have their minified versions (used YUI compressor).

If you want to test the script on different devises within your desktop browser, you can use a plugin for Firefox called User Agent Switcher, that you can download here.

Feel free to fork the project and improve it if necessary.

..and feel free to make a donation from this page 

Thursday, July 28, 2011

Installing Windows Virtual PC on Windows 7 Home Premium

Microsoft have replaced Virtual PC 2007 with “Windows Virtual PC”, but theoretically it is only supported with Windows 7 Professional and above. However, if you head over to the Windows Virtual PC website, and say that you have Windows 7 Professional, it enables the downloads of Windows XP Mode and Windows Virtual PC. You only need to download the Virtual PC part, which arrives as the rather cryptically named Windows6.1-KB958559-x86.msu. Simply double-click to install.

Once installed you may, like me, run into the issue that hardware assisted virtualization is not enabled in your BIOS. I have a Dell laptop, and it was a matter of hitting F12 on bootup and searching around for the option in the BIOS settings. More info on enabling HAV.

The final step was to load up one of the old Virtual PC 2007 vmc files I had lying around. This went smoothly, although my virtualized XP did attempt and fail to install new device drivers when it booted up. Windows Virtual PC adds a Virtual Machines folder under your user account from which you can set up a new virtual machine if you require. I haven’t done this yet, but I might give it a go later and attempt to get Ubuntu running (something which was notoriously difficult under VPC 2007 so hopefully the process is a bit smoother now).

Anyway, it’s nice that Microsoft have made this tool available for free, which is very useful for software testing, and even better that its usable on Win 7 Home Premium, without having to upgrade to Professional.

Thursday, July 21, 2011

Turn off Auto Play for pen drive


You can get rid of lot of viruses by turning off the autoplay option for your removable devices. To turn off auto play on your Windows 7 box use the following steps:
Autplay2
1. Go to Run
2. Type GPEDIT.MSC
3. Select COMPUTER CONFIGURATION >> Administrative Templates >> ALL Settings
4. Search for TURN OFF AUTOPLAY. Double click and Select "Enabled" from the radio options. You can also configure for All drives and for Only the CD-ROM and Removable devices.
5. Click "Apply" to apply your changes.
    Autplay1
    Happy Computing.

    Wednesday, November 3, 2010

    Computer Networking - Concepts and Terminologies

    Introduction

    This is a continuation of my series of articles on the terms and concepts that are frequently asked in IT interviews. This article is an attempt to discuss the salient terminologies and concepts related to Computer networking that are often asked in interviews. Although an article on Computer Networking concepts and terms would run for many pages, I have discussed only important ones to make it fit in one article.

    Computer Network

    A Computer Network implies two or more computers those are linked together through some software, hardware, etc for the purpose of exchanging data and information.

    Internet

    The Internet is a network of networks. It is "the worldwide, publicly accessible network of interconnected computer networks that transmit data by packet switching using the standard Internet Protocol (IP)."

    World Wide Web

    The World Wide Web or WWW is a hypertext based distributed information system. It "is the global network of hypertext (HTTP) servers that allow text, graphics, audio and video files to be mixed together." It is an "information space in which the items of interest, referred to as resources, are identified by global identifiers called Uniform Resource Identifiers (URI)." According to Tim Berners-Lee, inventor of the World Wide Web, "The World Wide Web is the universe of network-accessible information, an embodiment of human knowledge."

    Modem

    A modem is a modulator-demodulator device that is used for converting the transmission signals from digital to analog for transmission over voice-grade phone lines. While the digital signals are converted to a form suitable for transmission over analog communication at the source, the reverse happens at the destination where these analog signals are returned to their original digital form.

    Network Interface Controller

    A network card, network adapter or the Network Interface Controller (NIC) is a piece of computer hardware that facilitates the systems in a network to communicate.

    Broadcasting

    When the information transfer is from one system to many systems using the same means of transfer then such a network is known as a Broadcasting or Multicasting.

    Unicasting

    When the information transfer is from one system to any other single system using the same means of transfer then such a network is known as Point-to-Point or Unicasting.

    Bandwidth

    Network bandwidth or network throughput is a measure of the data transfer rate or the amount of data that can pass through a network interface over a specific period of time. This is expressed in bits per second or bps.

    Broadband

    This is a wide-band technology that is capable of supporting voice, video and data. It is "a transmission medium capable of supporting a wide range of frequencies, typically from audio up to video frequencies. It can carry multiple signals by dividing the total capacity of the medium into multiple, independent bandwidth channels, where each channel operates only on a specific range of frequencies."

    Integrated Services Digital Network (ISDN)

    Integrated Services Digital Network, an international standard for end-to-end digital transmission of voice, data, and signaling facilitates very high-speed data transfer over existing phone lines.

    Network Load Balancing

    Network Load Balancing may be defined as a technique that "distributes the network traffic along parallel paths to maximize the available network bandwidth while providing redundancy."

    Local Area Network

    LAN also known as Local Area Network are networks restricted on the bases of the area they cover. These networks stretch around an area of 10 meters to 1 km. "LANs enabled multiple users in a relatively small geographical area to exchange files and messages, as well as access shared resources such as file servers and printers." The commonly used LAN devices include repeaters, hubs, LAN extenders, bridges, LAN switches, and routers.

    Metropolitan Area Network

    MAN also known, as Metropolitan Area Network is a network that is larger than LANs spreading across an area of 1 km to 10kms. A simple example for this type of network is the branches of a bank spread across the city and are connected for information exchange.

    Wide Area Network

    WAN also known, as Wide Area Network is a network that is larger than a MAN, it spreads across an area of 100kms to 1000 kms. "A WAN is a data communications network that covers a relatively broad geographic area and that often uses transmission facilities provided by common carriers, such as telephone companies. WAN technologies generally function at the lower three layers of the OSI reference model: the physical layer, the data link layer, and the network layer." A simple example for these networks is the network of a huge IT company, which contains branches all over the world with all its branches connected to each other.

    Wireless Networks

    Wireless Networks are those networks wherein the interconnection between two systems is not physical. The computers that interchange information are not physically linked with wires.

    Bluetooth

    Bluetooth is a wireless network that has a short range and can be used to connect a system with its internal components like monitor, mouse, CPU, etc without actually having a plug in. Components that support the Bluetooth technology can be detected whenever they are in the detectable range.

    Routing

    When there are multiple paths between the sender and the receiver the best path for sending the information has to be chosen. The choice is made based on a number of criteria like the number of hops between the systems or on the physical distance between the systems. This process of finding the best path is known as routing.

    Topology

    Network topology refers to the arrangement of the nodes in a network. The following are the major types of network topologies:

    · Ring

    · Bus

    · Star

    MAC Address

    The Media Access Control or MAC address is the Network Interface Card address and is composed of 12 hexadecimal characters (0-9, A-F) and is defined as a unique identifier used to identify most network equipments and is used as the source and destination addresses for data packets on a LAN. Every network device in the world has a unique MAC address. The first 6 characters of the MAC address are unique to the manufacturer of the device.

    IP Address

    Every system that is connected to the internet is called a node and it is identified by a unique 32 - bit numeric address called the IP address or the Internet Protocol address. These addresses are created and governed by the Internet Assigned Numbers Authority or the IANA.

    Subnet

    A subnet is an identifiably separate part of an organization's network and is defined as "an interconnected, but independent segment of a network that is identified by its Internet Protocol (IP) address."

    Virtual LAN

    "A Virtual LAN, commonly known as a VLAN, is a method of creating independent logical networks within a physical network."

    Virtual Circuit

    A Virtual Circuit may be defined as a logical circuit that ensures that there is a reliable communication between two network devices. It is "a network service that provides connection-oriented service regardless of the underlying network structure."

    Domain Naming Service

    Domain Naming Service or DNS is a naming service that is used to name the nodes over a network for simplicity reasons. The domain name is actually a textual name that identifies a host in a network. The DNS servers have the DNS names stored along with their corresponding IP addresses.

    Protocol

    A Network Protocol implies that rules and regulations that govern how two devices can communicate in a network for the purpose of sharing data and information exchange. Network protocols are in other words, the language of communication amongst two network devices in a network. Typical examples of protocols include TCP/IP, SMTP, HTTP, SNMP, Telnet, FTP, etc.

    Ethernet

    Ethernet was designed and developed by the Xerox Corporation, DEC and Intel Corporation way back in 1976. It is a local-area network that uses the uses carrier sense multiple access collision detects (CSMA/CD) technology and the bus topology to provide a very reliable and fast data communication in a small geographic area.

    Carrier Sense Multiple Access / Collision Detection (CSMA)

    Carrier Sense Multiple Access is a set of rules that govern how the network devices respond at the time when a collision is detected, i.e., when two devices attempt to use a data channel simultaneously.

    Secure Sockets Layer

    Secure Sockets Layer or SSL is a frequently used protocol for managing the security of message transmission over the internet. It facilitates this by enabling the server and the client systems to exchange public keys to enable them to encode and decode the data and information that they exchange between themselves.

    Network Socket

    A socket is the end point of a two way communication between two systems running over a network.

    Network Port

    A port implies an unsigned integer that uniquely identifies a process running over a network. The following are some of the well known port numbers:

    Http 80

    Telnet 23

    SMTP 25

    SNPP 444

    DNS 53

    FTP (Data) 20

    FTP (Control) 21

    Router

    A router is a device that is used to route network data packets between two networks using some predefined algorithms. These algorithms are commonly known as routing algorithms.

    Repeater

    A repeater may be defined as a device that "regenerates and propagates the electric signals between two network segments."

    Firewall

    A Network Firewall comprises one or a group of two or more systems that prevents unauthorized network accesses by restricting the unwanted or unauthorized incoming or outgoing network traffic.

    Gateway

    A gateway joins two or more networks using a combination of the necessary hardware and software. "A gateway can translate information between different network data formats or network architectures."

    Packet

    A packet may be defined as a formatted block of data and or information for transmission over a network. These packets are broken into smaller packets for facilitating the transmission over the Internet. A network packet consists of the following:

    · A header

    · A trailer

    · A payload

    While the header and the trailer mark the beginning and the end of the packet, the payload contains the actual data to be transmitted.

    Network Switch

    A network switch is defined as a hardware device that is used to join multiple systems together at a low-level network protocol layer. It is a computer networking device that "connects network segments. It uses the logic of a Network bridge but allows a physical and logical star topology. It is often used to replace network hubs. A switch is also often referred to as an intelligent hub."

    Network Bridge

    A network bridge is used to connect two systems in a network that have identical configuration. It is an "abstract device that connects multiple network segments along the data link layer. An example of a bridge in a computer network is the network switch."

    Open Systems Interconnection or OSI Model

    The International Standards Organization or the ISO, proposed the OSI Reference Model, and it is known as Open Systems Interconnection as it is designed for systems that are open for communication. "The Open System Interconnection (OSI) reference model describes how information from a software application in one computer moves through a network medium to a software application in another computer. The OSI reference model is a conceptual model composed of seven layers, each specifying particular network functions." This is a seven layered design that depicts the typical network architecture and a conceptual framework for communication and how data can pass through one layer to another in such an architecture, the protocols involved, etc.

    The OSI Layers

    The OSI model describes the following seven layers in its architecture:

    · The Physical layer

    · The Data Link Layer

    · The Network Layer

    · The Transport Layer

    · The Session Layer

    · The Presentation Layer

    · The Application Layer

    The following diagram depicts the seven layers of the OSI Model.

    Figure 1

    The Physical Layer

    This is the lowest layer in the OSI model and deals with the transfer of raw bits across the network. "The physical layer defines the electrical, mechanical, procedural, and functional specifications for activating, maintaining, and deactivating the physical link between communicating network systems."

    The Data Link Layer

    The main function of the data link layer is to break up large amounts of information into packets and send the packets sequentially across a no error transmission medium and receive the acknowledgement packets from the receiver for the same. Another important function of this layer is to make the sender and the receiver compatible with each other by synchronizing the information between the two to avoid a fast sender – slow receiver problems and vice – versa

    The Network Layer

    The function of the Network layer is to see that all the packets that are sent or received have an error free network or an error free medium for the exchange of packets in general to have a good quality of service is the major function of the network layer.

    The Transport Layer

    The transport layer collects the information, splits it into packets and sends it to the network layer. It ensures that the data transferred is devoid of any errors and in the right sequence.

    The Session Layer

    The session layer is instrumental in establishing, controlling and terminating communication sessions. It should be noted that the "communication sessions consist of service requests and service responses that occur between applications located in different network devices."

    The Presentation layer

    The Presentation Layer of the OSI Model converts the incoming and outgoing data from one presentation format to another so as to ensure that it is readable across application layers of other systems.

    The Application Layer

    "This is the layer at which communication partners are identified, quality of service is identified, user authentication and privacy are considered, and any constraints on data syntax are identified."

     

    Web Design Company karimnagar, Web Designing warangal, Logo Design Company nizamabad, Indian Website Design Company, maddysoft.co.in