Sunteți pe pagina 1din 76

RC4 ENCRYPTION USING DYNAMIC KEYS AND VIRTUAL ENERGY FOR WIRELESS SENSOR NETWORKS

ABSTRACT:

Designing cost-efficient, secure network protocols for Wireless Sensor Networks (WSNs) is a challenging problem because sensors are resource-limited wireless devices. Since the communication cost is the most dominant factor in a sensors energy consumption, we introduce an energy-efficient Virtual Energy-Based Encryption and Keying (VEBEK) scheme for WSNs that significantly reduces the number of transmissions needed for rekeying to avoid stale keys. In addition to the goal of saving energy, minimal transmission is imperative for some military applications of WSNs where an adversary could be monitoring the wireless spectrum. VEBEK is a secure communication framework where sensed data is encoded using a scheme based on a permutation code generated via the RC4 encryption mechanism. The key to the RC4 encryption mechanism dynamically changes as a function of the residual virtual energy of the sensor. Thus, a one-time dynamic key is employed for one packet only and different keys are used for the successive packets of the stream. The intermediate nodes along the path to the sink are able to verify the authenticity and integrity of the incoming packets using a predicted value of the key generated by the senders virtual energy, thus requiring no need for specific rekeying messages.

INTRODUCTION:

Rapidly developed WSN technology is no longer nascent and will be used in a variety of application scenarios. Typical application areas include environmental, military, and commercial enterprises. For example, in a battlefield scenario, sensors may be used to detect the location of enemy sniper fire or to detect harmful chemical agents before they reach troops. In another potential scenario, sensor nodes forming a network under water could be used for oceanographic data collection, pollution monitoring, assisted navigation, military surveillance, and mine reconnaissance operations. Future improvements in technology will bring more sensor applications into our daily lives and the use of sensors will also evolve from merely capturing data to a system that can be used for real-time compound event alerting.

From a security standpoint, it is very important to provide authentic and accurate data to surrounding sensor nodes and to the sink to trigger time-critical responses (e.g., troop movement, evacuation, and first response deployment). Protocols should be resilient against false data injected into the network by malicious nodes. Otherwise, consequences for propagating false data or redundant data are costly, depleting limited network resources and wasting response efforts. However, securing sensor networks poses unique challenges to protocol builders because these tiny wireless devices are deployed in large numbers, usually in unattended environments, and are severely limited in their capabilities and resources (e.g., power, computational capacity, and memory). For instance, a typical sensor operates at the frequency of 2.4 GHz, has a data rate of 250 Kbps, 128 KB of program flash memory, 512 KB of memory for measurements, transmit power between 100 _W and 1 mW, and a communications range of 30 to 100 m. Therefore, protocol builders must be cautious about utilizing the limited resources onboard the sensors efficiently.

In this paper, we focus on keying mechanisms for WSNs. There are two fundamental key management schemes for WSNs: static and dynamic. In static key management schemes, key management functions (i.e., key generation and distribution) are handled statically. That is, the sensors have a fixed number of keys loaded either prior to or shortly after network deployment. On the other hand, dynamic key management schemes perform keying functions (rekeying)

either periodically or on demand as needed by the network. The sensors dynamically exchange keys to communicate. Although dynamic schemes are more attack resilient than static ones, one significant disadvantage is that they increase the communication overhead due to keys being refreshed or redistributed from time to time in the network. There are many reasons for key refreshment, including: updating keys after a key revocation has occurred, refreshing the key such that it does not become stale, or changing keys due to dynamic changes in the topology.

In this paper, we seek to minimize the overhead associated with refreshing keys to avoid them becoming stale. Because the communication cost is the most dominant factor in a sensors energy consumption the message transmission cost for rekeying is an important issue in a WSN deployment (as analyzed in the next section). Furthermore, for certain WSN applications (e.g., military applications), it may be very important to minimize the number of messages to decrease the probability of detection if deployed in an enemy territory. That is, being less chatty intuitively decreases the number of opportunities for malicious entities to eavesdrop or intercept packets. The purpose of this paper is to develop an efficient and secure communication framework for WSN applications. Specifically, in this paper, we introduce Virtual EnergyBased Encryption and Keying (VEBEK) for WSNs, which is primarily inspired by our previous work. VEBEKs secure communication framework provides a technique to verify data in line and drop false packets from malicious nodes, thus maintaining the health of the sensor network. VEBEK dynamically updates keys without exchanging messages for key renewals and embeds integrity into packets as opposed to enlarging the packet by appending message authentication codes (MACs). Specifically, each sensed data is protected using a simple encoding scheme based on a permutation code generated with the RC4 encryption scheme and sent toward the sink. The key to the encryption scheme dynamically changes as a function of the residual virtual energy of the sensor, thus requiring no need for rekeying.

Therefore, a one-time dynamic key is used for one message generated by the source sensor and different keys are used for the successive packets of the stream. The nodes forwarding the data along the path to the sink are able to verify the authenticity and integrity of the data and to provide non repudiation. The protocol is able to continue its operations under dire communication cases as it may be operating in a high-error-prone deployment area like under

water. VEBEK unbundles key generation from other security services, namely authentication, integrity, and non repudiation; thus, its flexible modular architecture allows for adoption of other encryption mechanisms. The paper proceeds as follows: To motivate our work, a preliminary analysis of the rekeying cost with and without explicit control messages is given in discusses the semantics of VEBEK. VEBEKs different operational modes are discussed in analytical framework and performance evaluation results including a comparison with other relevant works summarizes the design rationale and benefits of the VEBEK framework.

EXISTING SYSTEM:

An existing Dynamic Energy-based Encoding and Filtering framework to detect the injection of false data into a sensor network. Dynamic Energy-based that each sensed event report be encoded using a simple encoding scheme based on a keyed hash. The key to the hashing function dynamically changes as a function of the transient energy of the sensor, thus requiring no need for re-keying. Depending on the cost of transmission vs. computational cost of encoding, it may be important to remove data as quickly as possible. Accordingly, DEEF can provide authentication at the edge of the network or authentication inside of the sensor network. Depending on the optimal configuration, as the report is forwarded, each node along the way verifies the correctness of the encoding probabilistically and drops those that are invalid. We have evaluated DEEF's feasibility and performance through analysis our results show that DEEF, without incurring transmission overhead.

NETWORKING MODULE: Client-server computing or networking is a distributed application architecture that partitions tasks or workloads between service providers (servers) and service requesters, called clients. Often clients and servers operate over a computer network on separate hardware. A server machine is a high-performance host that is running one or more server programs which share its resources with clients. A client also shares any of its resources; Clients therefore initiate communication sessions with servers which await (listen to) incoming requests. WSN SECURITY: We focus on keying mechanisms for WSNs. There are two fundamental key management schemes for WSNs: static and dynamic. In static key management schemes, key management functions (i.e., key generation and distribution) are handled statically. That is, the sensors have a fixed number of keys loaded either prior to or shortly after network deployment. On the other hand, dynamic key management schemes perform keying functions (rekeying) either periodically or on demand as needed by the network. The sensors dynamically exchange keys to communicate. Although dynamic schemes are more attack resilient than static ones, one significant disadvantage is that they increase the communication overhead due to keys being refreshed or redistributed from time to time in the network. There are many reasons for key refreshment, including: updating keys after a key revocation has occurred, refreshing the key such that it does not become stale, or changing keys due to dynamic changes in the topology.

VIRTUAL ENERGY-BASED KEYING: The virtual energy-based keying module of the VEBEK framework is one of the primary contributions of this paper. It is essentially the method used for handling the keying process. It produces a dynamic key that is then fed into the crypto module.

In VEBEK, each sensor node has a certain virtual energy value when it is first deployed in the network. Sensor nodes traverse several functional states. The states mainly include node-stay-alive, packet reception, transmission, encoding, and decoding. As each of these

actions occurs, the virtual energy in a sensor node is depleted. The current value of the virtual energy in the node is used as the key to the key generation function. VEBEKs virtual energy-based keying module ensures that each detected packet2 is associated with a new unique key generated based on the transient value of the virtual energy. After the dynamic key is generated, it is passed to the crypto module, where the desired security services are implemented. Since a sensor node will be either forwarding some other sensors data or injecting its own data into the network, the set of actions and their associated energies for VEBEK includes packet reception (Erx), packet transmission (Etx), packet encoding (Eenc), packet decoding (Edec) energies, and the energy required to keep a node alive in the idle state (Ea). Specifically, the transient value of the virtual energy, Ev, is computed by decrementing the total of these predefined associated costs, Evc, from the previous virtual energy value. RESOURCE CRYPTO MODULE:

The crypto module in VEBEK employs a simple encoding process, which is essentially the process of permutation of the bits in the packet according to the dynamically created permutation code generated via RC4. The encoding is a simple encryption mechanism adopted for VEBEK.

However, VEBEKs flexible architecture allows for adoption of stronger encryption mechanisms in lieu of encoding. Last, the forwarding module handles the process of sending or receiving of encoded packets along the path to the sink. After the dynamic key is generated, it is passed to the crypto module, where the desired security services are implemented.

The process of key generation is initiated when data is sensed; thus, no explicit mechanism is needed to refresh or update keys. Moreover, the dynamic nature of the keys

makes it difficult for attackers to intercept enough packets to break the encoding algorithm.

Due to the resource constraints of WSNs, traditional digital signatures or encryption mechanisms requiring expensive cryptography is not viable. The scheme must be simple, yet effective. Thus, in this section, we introduce a simple encoding operation. The encoding operation is essentially the process of permutation of the bits in the packet, according to the dynamically created permutation code via the RC4 encryption mechanism.

OPERATIONAL MODES (VEBEK): The VEBEK protocol provides three security services authentication, integrity, and non repudiation. However, there are costs (communication, computation, and storage) associated providing these services. In reality, applications may have different security requirements. For instance, the security need of a military WSN application. The VEBEK framework also considers this need for flexibility and thus, supports two operational modes: VEBEK-I and VEBEK-II. The operational mode of VEBEK determines the number of nodes a particular sensor node must watch. Depending on the vigilance required inside the network, either of the operational modes can be configured for WSN applications.

VEBEK-I: In the VEBEK-I operational mode, all nodes watch their neighbors; whenever a packet is received from a neighbor sensor node, it is decoded and its authenticity and integrity are verified. Only legitimate packets are forwarded toward the sink. In this mode, we assume there exists a short window of time at initial deployment that an adversary is not able to compromise the network, because it takes time for an attacker to capture a node or get keys. During this period, route initialization information may be used by each node to decide which node to watch and a record r is stored for each of its one-hop neighbors in its watch-list. To obtain a neighbors initial energy value, a network-wise master key can be used to transmit this value during this period similar to the shared-key discovery phase of other dynamic key management schemes. Alternatively, sensors can be preloaded with the initial energy value.

VEBEK-II:

In the VEBEK-II operational mode, nodes in the network are configured to only watch some of the nodes in the network. Each node randomly picks r nodes to monitor and stores the corresponding state before deployment. As a packet leaves the source node (originating node or forwarding node) it passes through node(s) that watch it probabilistically. Threshold before actually classifying the packet as malicious if the packet is authentic, and this hop is not the final destination, the original packet is forwarded unless the node is currently bridging the network. In the bridging case, the original packet is re encoded with the virtual bridge energy and forwarded. Since this node is bridging the network, both virtual and perceived energy values are decremented accordingly. If the packet is illegitimate, which is classified as such after exhausting all the virtual perceived energy values within the virtual Key Search Threshold window, the packet is discarded. This process continues until the packet reaches the sink.

DATA FLOW DIAGRAM:

DFD:
Source

Use Key

Use Key

VEBEK I

RC4

VEBEK II

Encrypt Data

Encrypt Data

Destination

Class Diagram: Policy Complaint:

Source:

Destination:

Use case Diagram:

Source

Destination

VEBEK I

RC 4 VEBEK II

Encrypt Key

Encrypt Key

Destination

Sequence Diagram:
Source RC4 VEBEK I VEBEK II Encrypt Key Destination

Send Data

Send

Send

Encrypt

Encrypt

Destination

Activity Diagram: source


VEBEK I

if Rc4
VEBEK II

else
VEBEK I

Encrypt Key

Destination

SYSTEM STUDY:
FEASIBILITY STUDY The feasibility of the project is analyzed in this phase and business proposal is put forth with a very general plan for the project and some cost estimates. During system analysis the feasibility study of the proposed system is to be carried out. This is to ensure that the proposed system is not a burden to the company. For feasibility analysis, some understanding of the major requirements for the system is essential. Three key considerations involved in the feasibility analysis are ECONOMICAL FEASIBILITY TECHNICAL FEASIBILITY SOCIAL FEASIBILITY

ECONOMICAL FEASIBILITY This study is carried out to check the economic impact that the system will have on the organization. The amount of fund that the company can pour into the research and development of the system is limited. The expenditures must be justified. Thus the developed system as well within the budget and this was achieved because most of the technologies used are freely available. Only the customized products had to be purchased. TECHNICAL FEASIBILITY This study is carried out to check the technical feasibility, that is, the technical requirements of the system. Any system developed must not have a high demand on the available technical resources. This will lead to high demands on the available technical resources. This

will lead to high demands being placed on the client. The developed system must have a modest requirement, as only minimal or null changes are required for implementing this system. SOCIAL FEASIBILITY The aspect of study is to check the level of acceptance of the system by the user. This includes the process of training the user to use the system efficiently. The user must not feel threatened by the system, instead must accept it as a necessity. The level of acceptance by the users solely depends on the methods that are employed to educate the user about the system and to make him familiar with it. His level of confidence must be raised so that he is also able to make some constructive criticism, which is welcomed, as he is the final user of the system. SYSTEM TESTING The purpose of testing is to discover errors. Testing is the process of trying to discover every conceivable fault or weakness in a work product. It provides a way to check the functionality of components, sub assemblies, assemblies and/or a finished product It is the process of exercising software with the intent of ensuring that the Software system meets its requirements and user expectations and does not fail in an unacceptable manner. There are various types of test. Each test type addresses a specific testing requirement.

TYPES OF TESTS Unit testing Unit testing involves the design of test cases that validate that the internal program logic is functioning properly, and that program inputs produce valid outputs. All decision branches and internal code flow should be validated. It is the testing of individual software units of the application .it is done after the completion of an individual unit before integration. This is a structural testing, that relies on knowledge of its construction and is invasive. Unit tests perform basic tests at component level and test a specific business process, application, and/or system configuration. Unit tests ensure that each unique path of a business process performs accurately to the documented specifications and contains clearly defined inputs and expected results. Integration testing Integration tests are designed to test integrated software components to determine if they actually run as one program. Testing is event driven and is more concerned with the basic outcome of screens or fields. Integration tests demonstrate that although the components were individually satisfaction, as shown by successfully unit testing, the combination of components is correct and consistent. Integration testing is specifically aimed at arise from the combination of components. Functional test Functional tests provide systematic demonstrations that functions tested are available as specified by the business and technical requirements, system documentation, and user manuals. Functional testing is centered on the following items: Valid Input Invalid Input Functions Output Systems/Procedures : identified classes of valid input must be accepted. : identified classes of invalid input must be rejected. : identified functions must be exercised. : identified classes of application outputs must be exercised. : interfacing systems or procedures must be invoked. exposing the problems that

Organization and preparation of functional tests is focused on requirements, key functions, or special test cases. In addition, systematic coverage pertaining to identify Business process flows; data fields, predefined processes, and successive processes must be considered for testing. Before functional testing is complete, additional tests are identified and the effective value of current tests is determined. System Test System testing ensures that the entire integrated software system meets requirements. It tests a configuration to ensure known and predictable results. An example of system testing is the configuration oriented system integration test. System testing is based on process descriptions and flows, emphasizing pre-driven process links and integration points. White Box Testing White Box Testing is a testing in which in which the software tester has knowledge of the inner workings, structure and language of the software, or at least its purpose. It is purpose. It is used to test areas that cannot be reached from a black box level. Black Box Testing Black Box Testing is testing the software without any knowledge of the inner workings, structure or language of the module being tested. Black box tests, as most other kinds of tests, must be written from a definitive source document, such as specification or requirements document, such as specification or requirements document. It is a testing in which the software under test is treated, as a black box .you cannot see into it. The test provides inputs and responds to outputs without considering how the software works. Unit Testing: Unit testing is usually conducted as part of a combined code and unit test phase of the software lifecycle, although it is not uncommon for coding and unit testing to be conducted as two distinct phases.

Test strategy and approach Field testing will be performed manually and functional tests will be written in detail. Test objectives All field entries must work properly. Pages must be activated from the identified link. The entry screen, messages and responses must not be delayed.

Features to be tested Verify that the entries are of the correct format No duplicate entries should be allowed All links should take the user to the correct page.

6.2 Integration Testing Software integration testing is the incremental integration testing of two or more integrated software components on a single platform to produce failures caused by interface defects. The task of the integration test is to check that components or software applications, e.g. components in a software system or one step up software applications at the company level interact without error. Test Results: All the test cases mentioned above passed successfully. No defects encountered.

6.3 Acceptance Testing User Acceptance Testing is a critical phase of any project and requires significant participation by the end user. It also ensures that the system meets the functional requirements. Test Results: All the test cases mentioned above passed successfully. No defects encountered.

Software Environment Features Of .Net Microsoft .NET is a set of Microsoft software technologies for rapidly building and integrating XML Web services, Microsoft Windows-based applications, and Web solutions. The .NET Framework is a language-neutral platform for writing programs that can easily and securely interoperate. Theres no language barrier with .NET: there are numerous languages available to the developer including Managed C++, C#, Visual Basic and Java Script. The .NET framework provides the foundation for components to interact seamlessly, whether locally or remotely on different platforms. It standardizes common data types and communications protocols so that components created in different languages can easily interoperate. .NET is also the collective name given to various software components built upon the .NET platform. These will be both products (Visual Studio.NET and Windows.NET Server, for instance) and services (like Passport, .NET My Services, and so on). THE .NET FRAMEWORK The .NET Framework has two main parts: 1. The Common Language Runtime (CLR). 2. A hierarchical set of class libraries. The CLR is described as the execution engine of .NET. It provides the environment within which programs run. The most important features are Conversion from a low-level assembler-style language, called Intermediate Language (IL), into code native to the platform being executed on. Memory management, notably including garbage collection. Checking and enforcing security restrictions on the running code. Loading and executing programs, with version control and other such features. The following features of the .NET framework are also worth description:

Managed Code The code that targets .NET, and which contains certain extra Information - metadata to describe itself. Whilst both managed and unmanaged code can run in the runtime, only managed code contains the information that allows the CLR to guarantee, for instance, safe execution and interoperability. Managed Data With Managed Code comes Managed Data. CLR provides memory allocation and Deal location facilities, and garbage collection. Some .NET languages use Managed Data by default, such as C#, Visual Basic.NET and JScript.NET, whereas others, namely C++, do not. Targeting CLR can, depending on the language youre using, impose certain constraints on the features available. As with managed and unmanaged code, one can have both managed and unmanaged data in .NET applications - data that doesnt get garbage collected but instead is looked after by unmanaged code. Common Type System The CLR uses something called the Common Type System (CTS) to strictly enforce type-safety. This ensures that all classes are compatible with each other, by describing types in a common way. CTS define how types work within the runtime, which enables types in one language to interoperate with types in another language, including cross-language exception handling. As well as ensuring that types are only used in appropriate ways, the runtime also ensures that code doesnt attempt to access memory that hasnt been allocated to it. Common Language Specification The CLR provides built-in support for language interoperability. To ensure that you can develop managed code that can be fully used by developers using any programming language, a set of language features and rules for using them called the Common Language Specification (CLS) has been defined. Components that follow these rules and expose only CLS features are considered CLS-compliant.

THE CLASS LIBRARY .NET provides a single-rooted hierarchy of classes, containing over 7000 types. The root of the namespace is called System; this contains basic types like Byte, Double, Boolean, and String, as well as Object. All objects derive from System. Object. As well as objects, there are value types. Value types can be allocated on the stack, which can provide useful flexibility. There are also efficient means of converting value types to object types if and when necessary. The set of classes is pretty comprehensive, providing collections, file, screen, and network I/O, threading, and so on, as well as XML and database connectivity. The class library is subdivided into a number of sets (or namespaces), each providing distinct areas of functionality, with dependencies between the namespaces kept to a minimum.

LANGUAGES SUPPORTED BY .NET The multi-language capability of the .NET Framework and Visual Studio .NET enables developers to use their existing programming skills to build all types of applications and XML Web services. The .NET framework supports new versions of Microsofts old favorites Visual Basic and C++ (as VB.NET and Managed C++), but there are also a number of new additions to the family. Visual Basic .NET has been updated to include many new and improved language features that make it a powerful object-oriented programming language. These features include inheritance, interfaces, and overloading, among others. Visual Basic also now supports structured exception handling, custom attributes and also supports multi-threading. Visual Basic .NET is also CLS compliant, which means that any CLS-compliant language can use the classes, objects, and components you create in Visual Basic .NET.

Managed Extensions for C++ and attributed programming are just some of the enhancements made to the C++ language. Managed Extensions simplify the task of migrating existing C++ applications to the new .NET Framework. C# is Microsofts new language. Its a C-style language that is essentially C++ for Rapid Application Development. Unlike other languages, its specification is just the grammar of the language. It has no standard library of its own, and instead has been designed with the intention of using the .NET libraries as its own. Microsoft Visual J# .NET provides the easiest transition for Java-language developers into the world of XML Web Services and dramatically improves the interoperability of Javalanguage programs with existing software written in a variety of other programming languages. Active State has created Visual Perl and Visual Python, which enable .NET-aware applications to be built in either Perl or Python. Both products can be integrated into the Visual Studio .NET environment. Visual Perl includes support for Active States Perl Dev Kit. Other languages for which .NET compilers are available include FORTRAN COBOL Eiffel

Fig1 .Net Framework ASP.NET XML WEB SERVICES Base Class Libraries Common Language Runtime Operating System Windows Forms

C#.NET is also compliant with CLS (Common Language Specification) and supports structured exception handling. CLS is set of rules and constructs that are supported by the CLR (Common Language Runtime). CLR is the runtime environment provided by the .NET Framework; it manages the execution of the code and also makes the development process easier by providing services. C#.NET is a CLS-compliant language. Any objects, classes, or components that created in C#.NET can be used in any other CLS-compliant language. In addition, we can use objects, classes, and components created in other CLS-compliant languages in C#.NET .The use of CLS ensures complete interoperability among applications, regardless of the languages used to create the application. CONSTRUCTORS AND DESTRUCTORS: Constructors are used to initialize objects, whereas destructors are used to destroy them. In other words, destructors are used to release the resources allocated to the object. In C#.NET the sub finalize procedure is available. The sub finalize procedure is used to complete the tasks that must be performed when an object is destroyed. The sub finalize procedure is called automatically when an object is destroyed. In addition, the sub finalize procedure can be called only from the class it belongs to or from derived classes.

GARBAGE COLLECTION Garbage Collection is another new feature in C#.NET. The .NET Framework monitors allocated resources, such as objects and variables. In addition, the .NET Framework automatically releases memory for reuse by destroying objects that are no longer in use. In C#.NET, the garbage collector checks for the objects that are not currently in use by applications. When the garbage collector comes across an object that is marked for garbage collection, it releases the memory occupied by the object. OVERLOADING Overloading is another feature in C#. Overloading enables us to define multiple procedures with the same name, where each procedure has a different set of arguments. Besides using overloading for procedures, we can use it for constructors and properties in a class. MULTITHREADING: C#.NET also supports multithreading. An application that supports multithreading can handle multiple tasks simultaneously, we can use multithreading to decrease the time taken by an application to respond to user interaction. STRUCTURED EXCEPTION HANDLING C#.NET supports structured handling, which enables us to detect and remove errors at runtime. In C#.NET, we need to use TryCatchFinally statements to create exception handlers. Using TryCatchFinally statements, we can create robust and effective exception handlers to improve the performance of our application. THE .NET FRAMEWORK The .NET Framework is a new computing platform that simplifies application development in the highly distributed environment of the Internet.

OBJECTIVES OF. NET FRAMEWORK 1. To provide a consistent object-oriented programming environment whether object codes is stored and executed locally on Internet-distributed, or executed remotely. 2. To provide a code-execution environment to minimizes software deployment and guarantees safe execution of code. 3. Eliminates the performance problems. There are different types of application, such as Windows-based applications and Web-based applications.

4.3 Features of SQL-SERVER The OLAP Services feature available in SQL Server version 7.0 is now called SQL Server 2000 Analysis Services. The term OLAP Services has been replaced with the term Analysis Services. Analysis Services also includes a new data mining component. The Repository component available in SQL Server version 7.0 is now called Microsoft SQL Server 2000 Meta Data Services. References to the component now use the term Meta Data Services. The term repository is used only in reference to the repository engine within Meta Data Services SQL-SERVER database consist of six type of objects, They are, 1. TABLE 2. QUERY 3. FORM 4. REPORT 5. MACRO

TABLE: A database is a collection of data about a specific topic. VIEWS OF TABLE: We can work with a table in two types, 1. Design View 2. Datasheet View Design View To build or modify the structure of a table we work in the table design view. We can specify what kind of data will be hold. Datasheet View To add, edit or analyses the data itself we work in tables datasheet view mode. QUERY: A query is a question that has to be asked the data. Access gathers data that answers the question from one or more table. The data that make up the answer is either dynaset (if you edit it) or a snapshot (it cannot be edited).Each time we run query, we get latest information in the dynaset. Access either displays the dynaset or snapshot for us to view or perform an action on it, such as deleting or updating.

SAMLE CODE:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Sockets; using System.IO;

namespace Resequencing { public partial class Server : Form { public Server() { InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) {

private void BtnStartServer_Click(object sender, EventArgs e) { if (FTServerCode1.receivedPath != null) { backgroundWorker1.RunWorkerAsync(); backgroundWorker2.RunWorkerAsync(); backgroundWorker3.RunWorkerAsync(); lblserver.BackColor = Color.LimeGreen; } else { MessageBox.Show("Please select file receiving path"); } } private void BtnLocation_Click(object sender, EventArgs e) { FolderBrowserDialog fd = new FolderBrowserDialog(); if (fd.ShowDialog() == DialogResult.OK) { FTServerCode1.receivedPath = fd.SelectedPath; FTServerCode2.receivedPath = fd.SelectedPath; FTServerCode3.receivedPath = fd.SelectedPath; }

} FTServerCode1 obj1 = new FTServerCode1(); FTServerCode2 obj2 = new FTServerCode2(); FTServerCode3 obj3 = new FTServerCode3(); private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { obj1.StartServer();

} private void timer1_Tick(object sender, EventArgs e) { FTServerCode1.destip = txtIp1.Text; FTServerCode2.destip = txtIp2.Text; FTServerCode3.destip = txtIp3.Text; if (FTServerCode1.filefrm1 == "0") { lblc11.BackColor = Color.LimeGreen; FTServerCode1.timedelay[0] += FTServerCode1.tcalc; //ac1 = "y"; } else if (FTServerCode1.filefrm1 == "1") { FTServerCode1.timedelay[1] += FTServerCode1.tcalc; if (FTServerCode1.colc11 == null) {

FTServerCode1.timedelay[0] += FTServerCode1.tcalc; lblc11.BackColor = Color.Blue; }

lblc12.BackColor = Color.LimeGreen; // ac2 = "y"; } else if (FTServerCode1.filefrm1 == "2") { FTServerCode1.timedelay[2] += FTServerCode1.tcalc; if (FTServerCode1.colc11 == null) { FTServerCode1.timedelay[0] += FTServerCode1.tcalc; lblc11.BackColor = Color.Blue; } if (FTServerCode1.colc12 == null) { FTServerCode1.timedelay[1] += FTServerCode1.tcalc;

lblc12.BackColor = Color.Blue; } lblc13.BackColor = Color.LimeGreen; // ac3 = "y"; } else if (FTServerCode1.filefrm1 == "3")

{ FTServerCode1.timedelay[3] += FTServerCode1.tcalc; if (FTServerCode1.colc11 == null) { FTServerCode1.timedelay[0] += FTServerCode1.tcalc; lblc11.BackColor = Color.Blue; } if (FTServerCode1.colc12 == null) { FTServerCode1.timedelay[1] += FTServerCode1.tcalc;

lblc12.BackColor = Color.Blue; } if (FTServerCode1.colc13 == null) { FTServerCode1.timedelay[2] += FTServerCode1.tcalc; lblc13.BackColor = Color.Blue; } lblc14.BackColor = Color.LimeGreen; //ac4 = "y"; } else if (FTServerCode1.filefrm1 == "4") { FTServerCode1.timedelay[4] += FTServerCode1.tcalc; if (FTServerCode1.colc11 == null)

{ FTServerCode1.timedelay[0] += FTServerCode1.tcalc; lblc11.BackColor = Color.Blue; } if (FTServerCode1.colc12 == null) { FTServerCode1.timedelay[1] += FTServerCode1.tcalc; lblc12.BackColor = Color.Blue; } if (FTServerCode1.colc13 == null) { FTServerCode1.timedelay[2] += FTServerCode1.tcalc; lblc13.BackColor = Color.Blue; } if (FTServerCode1.colc14 == null) { FTServerCode1.timedelay[3] += FTServerCode1.tcalc;

lblc14.BackColor = Color.Blue; } lblc15.BackColor = Color.LimeGreen; //ac5 = "y"; } else if (FTServerCode1.filefrm1 == "5") {

FTServerCode1.timedelay[5] += FTServerCode1.tcalc;

lblc16.BackColor = Color.LimeGreen; // ac6 = "y"; } else if (FTServerCode1.filefrm1 == "6") { FTServerCode1.timedelay[6] += FTServerCode1.tcalc;

if (FTServerCode1.colc16 == null) {

lblc16.BackColor = Color.Blue; } lblc17.BackColor = Color.LimeGreen; //ac7 = "y"; } else if (FTServerCode1.filefrm1 == "7") { FTServerCode1.timedelay[7] += FTServerCode1.tcalc; if (FTServerCode1.colc16 == null) { FTServerCode1.timedelay[6] += FTServerCode1.tcalc; lblc16.BackColor = Color.Blue; }

if (FTServerCode1.colc17 == null) { FTServerCode1.timedelay[7] += FTServerCode1.tcalc;

lblc17.BackColor = Color.Blue; } lblc18.BackColor = Color.LimeGreen; //ac8 = "y"; } else if (FTServerCode1.filefrm1 == "8") { FTServerCode1.timedelay[8] += FTServerCode1.tcalc; if (FTServerCode1.colc16 == null) { FTServerCode1.timedelay[6] += FTServerCode1.tcalc; lblc16.BackColor = Color.Blue; } if (FTServerCode1.colc17 == null) { FTServerCode1.timedelay[7] += FTServerCode1.tcalc; lblc17.BackColor = Color.Blue; } if (FTServerCode1.colc18 == null) { FTServerCode1.timedelay[8] += FTServerCode1.tcalc;

lblc18.BackColor = Color.Blue; } lblc19.BackColor = Color.LimeGreen; //ac9 = "y"; } else if (FTServerCode1.filefrm1 == "9") { FTServerCode1.timedelay[9] += FTServerCode1.tcalc; if (FTServerCode1.colc16 == null) { FTServerCode1.timedelay[6] += FTServerCode1.tcalc;

lblc16.BackColor = Color.Blue; } if (FTServerCode1.colc17 == null) { FTServerCode1.timedelay[7] += FTServerCode1.tcalc;

lblc17.BackColor = Color.Blue; } if (FTServerCode1.colc18 == null) { FTServerCode1.timedelay[8] += FTServerCode1.tcalc; lblc18.BackColor = Color.Blue; }

if (FTServerCode1.colc19 == null) { FTServerCode1.timedelay[9] += FTServerCode1.tcalc; lblc19.BackColor = Color.Blue; } lblc110.BackColor = Color.LimeGreen; //ac10 = "y"; }

// send(); }

private void timer2_Tick(object sender, EventArgs e) { if (FTServerCode2.filefrm2 == "0") { FTServerCode2.timedelay[0] += FTServerCode2.tcalc; lblc21.BackColor = Color.LimeGreen; //ac1 = "y"; } else if (FTServerCode2.filefrm2 == "1") { FTServerCode2.timedelay[1] += FTServerCode2.tcalc; if (FTServerCode2.colc21 == null) {

FTServerCode2.timedelay[0] += FTServerCode2.tcalc; lblc21.BackColor = Color.Blue; }

lblc22.BackColor = Color.LimeGreen; // ac2 = "y"; } else if (FTServerCode2.filefrm2 == "2") { FTServerCode2.timedelay[2] += FTServerCode2.tcalc; edelay[7] += FTServerCode3.tcalc; if (FTServerCode3.colc36 == null) { FTServerCode3.timedelay[6] += FTServerCode3.tcalc;

lblc36.BackColor = Color.Blue; } if (FTServerCode3.colc37 == null) { FTServerCode3.timedelay[7] += FTServerCode3.tcalc; lblc37.BackColor = Color.Blue; } lblc38.BackColor = Color.LimeGreen; //ac8 = "y"; }

else if (FTServerCode3.filefrm3 == "8") { FTServerCode3.timedelay[8] += FTServerCode3.tcalc; if (FTServerCode3.colc36 == null) { FTServerCode3.timedelay[6] += FTServerCode3.tcalc; lblc36.BackColor = Color.Blue; } if (FTServerCode3.colc37 == null) { FTServerCode3.timedelay[7] += FTServerCode3.tcalc; lblc37.BackColor = Color.Blue; } if (FTServerCode3.colc38 == null) { FTServerCode3.timedelay[8] += FTServerCode3.tcalc; lblc38.BackColor = Color.Blue; } lblc39.BackColor = Color.LimeGreen; //ac9 = "y"; } else if (FTServerCode3.filefrm3 == "9") { FTServerCode3.timedelay[9] += FTServerCode3.tcalc; if (FTServerCode3.colc36 == null)

{ FTServerCode3.timedelay[6] += FTServerCode3.tcalc; lblc36.BackColor = Color.Blue; } if (FTServerCode3.colc37 == null) { FTServerCode3.timedelay[7] += FTServerCode3.tcalc; lblc37.BackColor = Color.Blue; } if (FTServerCode3.colc38 == null) { FTServerCode3.timedelay[8] += FTServerCode3.tcalc;

lblc38.BackColor = Color.Blue; } if (FTServerCode3.colc39 == null) { FTServerCode3.timedelay[9] += FTServerCode3.tcalc;

lblc39.BackColor = Color.Blue; } lblc310.BackColor = Color.LimeGreen; //ac10 = "y"; }

private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { obj2.StartServer();

private void backgroundWorker3_DoWork(object sender, DoWorkEventArgs e) { obj3.StartServer(); }

private void btn1_Click(object sender, EventArgs e) { Report_1 r = new Report_1(); r.label11.Text = FTServerCode1.timedelay[0].ToString() + " MilliSeconds."; r.label12.Text = FTServerCode1.timedelay[1].ToString() + " MilliSeconds."; r.label13.Text = FTServerCode1.timedelay[2].ToString() + " MilliSeconds."; r.label14.Text = FTServerCode1.timedelay[3].ToString() + " MilliSeconds."; r.label15.Text = FTServerCode1.timedelay[4].ToString() + " MilliSeconds."; r.label16.Text = FTServerCode1.timedelay[5].ToString() + " MilliSeconds."; r.label17.Text = FTServerCode1.timedelay[6].ToString() + " MilliSeconds."; r.label18.Text = FTServerCode1.timedelay[7].ToString() + " MilliSeconds."; r.label19.Text = FTServerCode1.timedelay[8].ToString() + " MilliSeconds.";

r.label20.Text = FTServerCode1.timedelay[9].ToString() + " MilliSeconds."; r.Show(); }

private void btn2_Click(object sender, EventArgs e) { Report_For_Chennal_2 r = new Report_For_Chennal_2(); r.label11.Text = FTServerCode2.timedelay[0].ToString() + " MilliSeconds."; r.label12.Text = FTServerCode2.timedelay[1].ToString() + " MilliSeconds."; r.label13.Text = FTServerCode2.timedelay[2].ToString() + " MilliSeconds."; r.label14.Text = FTServerCode2.timedelay[3].ToString() + " MilliSeconds."; r.label15.Text = FTServerCode2.timedelay[4].ToString() + " MilliSeconds."; r.label16.Text = FTServerCode2.timedelay[5].ToString() + " MilliSeconds."; r.label17.Text = FTServerCode2.timedelay[6].ToString() + " MilliSeconds."; r.label18.Text = FTServerCode2.timedelay[7].ToString() + " MilliSeconds."; r.label19.Text = FTServerCode2.timedelay[8].ToString() + " MilliSeconds."; r.label20.Text = FTServerCode2.timedelay[9].ToString() + " MilliSeconds."; r.Show(); }

private void btn3_Click(object sender, EventArgs e) { Report_For_Chennal_3 r = new Report_For_Chennal_3(); r.label11.Text = FTServerCode3.timedelay[0].ToString() + " MilliSeconds."; r.label12.Text = FTServerCode3.timedelay[1].ToString() + " MilliSeconds.";

r.label13.Text = FTServerCode3.timedelay[2].ToString() + " MilliSeconds."; r.label14.Text = FTServerCode3.timedelay[3].ToString() + " MilliSeconds."; r.label15.Text = FTServerCode3.timedelay[4].ToString() + " MilliSeconds."; r.label16.Text = FTServerCode3.timedelay[5].ToString() + " MilliSeconds."; r.label17.Text = FTServerCode3.timedelay[6].ToString() + " MilliSeconds."; r.label18.Text = FTServerCode3.timedelay[7].ToString() + " MilliSeconds."; r.label19.Text = FTServerCode3.timedelay[8].ToString() + " MilliSeconds."; r.label20.Text = FTServerCode3.timedelay[9].ToString() + " MilliSeconds."; r.Show(); } } //Channel 1

class FTServerCode1 { IPEndPoint ipEnd; Socket sock; string ser1; string fileDes, fileini; int len; byte[] data1; byte[] data2; byte[] data3; byte[] data4; byte[] data5;

byte[] data6; byte[] data7; byte[] data8; byte[] data9; byte[] data10; byte[] write; int fsize1, fsize2, fsize3, fsize4, fsize5, fsize6, fsize7, fsize8, fsize9, fsize10; double tstart; double tend;

public static string[] path = null; public static string filefrm1; public static string destip; string akc; public FTServerCode1() { IPHostEntry ipEntry = Dns.GetHostEntry(Environment.MachineName); IPAddress IpAddr = ipEntry.AddressList[0]; ipEnd = new IPEndPoint(IpAddr, 5); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); sock.Bind(ipEnd); } public static string receivedPath; public static string curMsg = "Stopped"; public static string colc11;

public static string colc12; public static string colc13; public static string colc14; public static string colc15; public static string colc16; public static string colc17; public static string colc18; public static string colc19; public static string colc110; public static double tcalc; public static double[] timedelay=new double[10]; public void StartServer() { try {

sock.Listen(100);

Socket clientSock = sock.Accept();

byte[] clientData = new byte[1024 * 15000];

int receivedBytesLen = clientSock.Receive(clientData); curMsg = "Receiving data...";

filefrm1 = Encoding.ASCII.GetString(clientData, 0, 1); tstart = Convert.ToDouble(DateTime.Now.Millisecond); if (filefrm1 == "0") { colc11 = "R"; data1 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data1, 0, receivedBytesLen - 1); akc = "0"; fsize1 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm1 == "1") { colc12 = "R"; data2 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data2, 0, receivedBytesLen - 1); akc = "1"; fsize2 = receivedBytesLen - 1;

send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm1 == "2") { colc13 = "R"; data3 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data3, 0, receivedBytesLen - 1); akc = "2"; fsize3 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm1 == "3")

{ colc14 = "R"; data4 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data4, 0, receivedBytesLen - 1); akc = "3"; fsize4 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm1 == "4") { colc15 = "R"; data5 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data5, 0, receivedBytesLen - 1); akc = "4"; fsize5 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend;

if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm1 == "5") { colc16 = "R"; data6 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data6, 0, receivedBytesLen - 1); akc = "5"; fsize6 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm1 == "6") { colc17 = "R"; data7 = new byte[receivedBytesLen - 1];

Array.Copy(clientData, 1, data7, 0, receivedBytesLen - 1); akc = "6"; fsize7 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm1 == "7") { colc18 = "R"; data8 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data8, 0, receivedBytesLen - 1); akc = "7"; fsize8 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save();

} } else if (filefrm1 == "8") { colc19 = "R"; data9 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data9, 0, receivedBytesLen - 1); akc = "8"; fsize9 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm1 == "9") { colc110 = "R"; data10 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data10, 0, receivedBytesLen - 1); akc = "9"; fsize10 = receivedBytesLen - 1;

send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend;

if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } clientSock.Close();

StartServer();

curMsg = "Reeived & Saved file; Server Stopped.";

} catch (Exception ex) { curMsg = "File Receving error."; } }

private void save() { write = new byte[data1.Length + data2.Length + data3.Length + data4.Length + data5.Length + data6.Length + data7.Length + data8.Length + data9.Length + data10.Length]; Array.Copy(data1, 0, write, 0, data1.Length); Array.Copy(data2, 0, write, fsize1, data2.Length); Array.Copy(data3, 0, write, fsize1 + fsize2, data3.Length); Array.Copy(data4, 0, write, fsize1 + fsize2 + fsize3, data4.Length); Array.Copy(data5, 0, write, fsize1 + fsize2 + fsize3 + fsize4, data5.Length); Array.Copy(data6, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5, data6.Length); Array.Copy(data7, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6, data7.Length); Array.Copy(data8, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7, data8.Length); Array.Copy(data9, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7 + fsize8, data9.Length); Array.Copy(data10, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7 + fsize8 + fsize9, data10.Length); if (System.IO.Directory.Exists(receivedPath + "/SYS1") == false) { System.IO.Directory.CreateDirectory(receivedPath + "/SYS1"); } int fileNameLen = BitConverter.ToInt32(write, 0); string fileName = Encoding.ASCII.GetString(write, 4, fileNameLen);

BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + "/SYS1/" + fileName, FileMode.Append)); ;

bWrite.Write(write, 4 + fileNameLen, write.Length - 4 - fileNameLen);

curMsg = "Saving file...";

bWrite.Close(); } public void send() { try { IPAddress[] ipAddress = Dns.GetHostAddresses(destip ); IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], 6); Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); byte[] ackn = Encoding.ASCII.GetBytes(akc); clientSock.Connect(ipEnd); clientSock.Send(ackn); clientSock.Close();

catch (Exception ex) { if (ex.Message == "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond")

{ //lblError.Text = ""; //lblError.Text = "No Such System Available Try other IP"; } else { if (ex.Message == "No connection could be made because the target machine actively refused it") { //lblError.Text = ""; //lblError.Text = "File Sending fail. Because server not running."; } else { //lblError.Text = ""; //lblError.Text = "File Sending fail." + ex.Message; } } } } } } //Chennal 2

class FTServerCode2

{ IPEndPoint ipEnd; Socket sock; string ser1; string fileDes, fileini; int len; byte[] data1; byte[] data2; byte[] data3; byte[] data4; byte[] data5; byte[] data6; byte[] data7; byte[] data8; byte[] data9; byte[] data10; byte[] write; int fsize1, fsize2, fsize3, fsize4, fsize5, fsize6, fsize7, fsize8, fsize9, fsize10; public static string[] path = null; public static string filefrm2; public static string destip;

string akc; double tstart; double tend;

public FTServerCode2() { IPHostEntry ipEntry = Dns.GetHostEntry(Environment.MachineName); IPAddress IpAddr = ipEntry.AddressList[0]; ipEnd = new IPEndPoint(IpAddr, 7); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); sock.Bind(ipEnd); } public static string receivedPath; public static string curMsg = "Stopped"; public static string colc21; public static string colc22; public static string colc23; public static string colc24; public static string colc25; public static string colc26; public static string colc27; public static string colc28; public static string colc29; public static string colc210; public static double tcalc; public static double[] timedelay = new double[10]; public void StartServer() { try

sock.Listen(100);

Socket clientSock = sock.Accept();

byte[] clientData = new byte[1024 * 15000];

int receivedBytesLen = clientSock.Receive(clientData); tstart = Convert.ToDouble(DateTime.Now.Millisecond); curMsg = "Receiving data..."; filefrm2 = Encoding.ASCII.GetString(clientData, 0, 1); if (filefrm2 == "0") { colc21 = "R"; data1 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data1, 0, receivedBytesLen - 1); akc = "0"; fsize1 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null)

{ save(); } } else if (filefrm2 == "1") { colc22 = "R"; data2 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data2, 0, receivedBytesLen - 1); akc = "1"; fsize2 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm2 == "2") { colc23 = "R"; data3 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data3, 0, receivedBytesLen - 1);

akc = "2"; fsize3 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm2 == "3") { colc24 = "R"; data4 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data4, 0, receivedBytesLen - 1); akc = "3"; fsize4 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); }

} else if (filefrm2 == "4") { colc25 = "R"; data5 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data5, 0, receivedBytesLen - 1); akc = "4"; fsize5 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm2 == "5") { colc26 = "R"; data6 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data6, 0, receivedBytesLen - 1); akc = "5"; fsize6 = receivedBytesLen - 1; send();

tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm2 == "6") { colc27 = "R"; data7 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data7, 0, receivedBytesLen - 1); akc = "6"; fsize7 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm2 == "7") {

colc28 = "R"; data8 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data8, 0, receivedBytesLen - 1); akc = "7"; fsize8 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm2 == "8") { colc29 = "R"; data9 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data9, 0, receivedBytesLen - 1); akc = "8"; fsize9 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null)

{ save(); } } else if (filefrm2 == "9") { colc210 = "R"; data10 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data10, 0, receivedBytesLen - 1); akc = "9"; fsize10 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend;

if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } clientSock.Close();

StartServer();

curMsg = "Reeived & Saved file; Server Stopped.";

} catch (Exception ex) { curMsg = "File Receving error."; } } private void save() { write = new byte[data1.Length + data2.Length + data3.Length + data4.Length + data5.Length + data6.Length + data7.Length + data8.Length + data9.Length + data10.Length]; Array.Copy(data1, 0, write, 0, data1.Length); Array.Copy(data2, 0, write, fsize1, data2.Length); Array.Copy(data3, 0, write, fsize1 + fsize2, data3.Length); Array.Copy(data4, 0, write, fsize1 + fsize2 + fsize3, data4.Length); Array.Copy(data5, 0, write, fsize1 + fsize2 + fsize3 + fsize4, data5.Length); Array.Copy(data6, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5, data6.Length); Array.Copy(data7, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6, data7.Length); Array.Copy(data8, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7, data8.Length); Array.Copy(data9, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7 + fsize8, data9.Length);

Array.Copy(data10, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7 + fsize8 + fsize9, data10.Length); if (System.IO.Directory.Exists(receivedPath + "/SYS2") == false) { System.IO.Directory.CreateDirectory(receivedPath + "/SYS2"); }

int fileNameLen = BitConverter.ToInt32(write, 0); else if (filefrm3 == "8") { colc39 = "R"; data9 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data9, 0, receivedBytesLen - 1); akc = "8"; fsize9 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend; if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } else if (filefrm3 == "9") {

colc310 = "R"; data10 = new byte[receivedBytesLen - 1]; Array.Copy(clientData, 1, data10, 0, receivedBytesLen - 1); akc = "9"; fsize10 = receivedBytesLen - 1; send(); tend = tstart - Convert.ToDouble(DateTime.Now.Millisecond) / 1000; tcalc = tend;

if (data1 != null && data2 != null && data3 != null && data4 != null && data5 != null && data6 != null && data7 != null && data8 != null && data9 != null && data10 != null) { save(); } } clientSock.Close();

StartServer();

curMsg = "Reeived & Saved file; Server Stopped.";

catch (Exception ex) { curMsg = "File Receving error."; } } private void save() { write = new byte[data1.Length + data2.Length + data3.Length + data4.Length + data5.Length + data6.Length + data7.Length + data8.Length + data9.Length + data10.Length]; Array.Copy(data1, 0, write, 0, data1.Length); Array.Copy(data2, 0, write, fsize1, data2.Length); Array.Copy(data3, 0, write, fsize1 + fsize2, data3.Length); Array.Copy(data4, 0, write, fsize1 + fsize2 + fsize3, data4.Length); Array.Copy(data5, 0, write, fsize1 + fsize2 + fsize3 + fsize4, data5.Length); Array.Copy(data6, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5, data6.Length); Array.Copy(data7, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6, data7.Length); Array.Copy(data8, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7, data8.Length); Array.Copy(data9, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7 + fsize8, data9.Length); Array.Copy(data10, 0, write, fsize1 + fsize2 + fsize3 + fsize4 + fsize5 + fsize6 + fsize7 + fsize8 + fsize9, data10.Length); if (System.IO.Directory.Exists(receivedPath + "/SYS3") == false) { System.IO.Directory.CreateDirectory(receivedPath + "/SYS3"); }

int fileNameLen = BitConverter.ToInt32(write, 0); string fileName = Encoding.ASCII.GetString(write, 4, fileNameLen);

BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + "/SYS3/" + fileName, FileMode.Append)); ; bWrite.Write(write, 4 + fileNameLen, write.Length - 4 - fileNameLen);

curMsg = "Saving file...";

bWrite.Close(); } public void send() { try { IPAddress[] ipAddress = Dns.GetHostAddresses(destip); IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], 10); Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); byte[] ackn = Encoding.ASCII.GetBytes(akc); clientSock.Connect(ipEnd); clientSock.Send(ackn); clientSock.Close();

catch (Exception ex) { if (ex.Message == "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond") { //lblError.Text = ""; //lblError.Text = "No Such System Available Try other IP"; } else { if (ex.Message == "No connection could be made because the target machine actively refused it") { //lblError.Text = ""; //lblError.Text = "File Sending fail. Because server not running."; } else { //lblError.Text = ""; //lblError.Text = "File Sending fail." + ex.Message; } }

SAMPLE SCREEN:

CONCLUSION:

Communication is very costly for wireless sensor networks (WSNs) and for certain WSN applications. Independent of the goal of saving energy, it may be very important to minimize the exchange of messages (e.g., military scenarios). To address these concerns, we presented a secure communication framework for WSNs called Virtual Energy- Based Encryption and Keying. In comparison with other key management schemes, VEBEK has the following benefits: 1) it does not exchange control messages for key renewals and is therefore able to save more energy and is less chatty, 2) it uses one key per message so successive packets of the stream use different keysmaking VEBEK more resilient to certain attacks (e.g., replay attacks, brute-force attacks, and masquerade attacks), and 3) it unbundles key generation from security services, providing a flexible modular architecture that allows for an easy adoption of different key-based encryption or hashing schemes. We have evaluated VEBEKs feasibility and performance through both theoretical analysis and simulations. Our results show that different operational modes of VEBEK (I and II) can be configured to provide optimal performance in a variety of network configurations depending largely on the application of the sensor network.

REFERENCES: [1] I.F. Akyildiz, W. Su, Y. Sankarasubramaniam, and E. Cayirci, Wireless Sensor Networks: A Survey, Computer Networks, vol. 38, no. 4, pp. 393-422, Mar. 2002. [2] C. Vu, R. Beyah, and Y. Li, A Composite Event Detection in Wireless Sensor Networks, Proc. IEEE Intl Performance, Computing, and Comm. Conf. (IPCCC 07), Apr. 2007. [3] S. Uluagac, C. Lee, R. Beyah, and J. Copeland, Designing Secure Protocols for Wireless Sensor Networks, Wireless Algorithms, Systems, and Applications, vol. 5258, pp. 503-514, Springer, 2008.

[4] Crossbow Technology, http://www.xbow.com, 2008. [5] G.J. Pottie and W.J. Kaiser, Wireless Integrated Network Sensors, Comm. ACM, vol. 43, no. 5, pp. 51-58, 2000. [6] R. Roman, C. Alcaraz, and J. Lopez, A Survey of Cryptographic Primitives and Implementations for Hardware-Constrained Sensor Network Nodes, Mobile Networks and Applications, vol. 12, no. 4, pp. 231-244, Aug. 2007. [7] H. Hou, C. Corbett, Y. Li, and R. Beyah, Dynamic Energy-Based Encoding and Filtering in Sensor Networks, Proc. IEEE Military Comm. Conf. (MILCOM 07), Oct. 2007. [8] L. Eschenauer and V.D. Gligor, A Key-Management Scheme for Distributed Sensor Networks, Proc. Ninth ACM Conf. Computer and Comm. Security, pp. 41-4, 2002. [9] M. Eltoweissy, M. Moharrum, and R. Mukkamala, Dynamic Key Management in Sensor Networks, IEEE Comm. Magazine, vol. 44, no. 4, pp. 122-130, Apr. 2006. [10] M. Zorzi and R. Rao, Geographic Random Forwarding (GeRaF) for Ad Hoc and Sensor Networks: Multihop Performance, IEEE Trans. Mobile Computing, vol. 2, no. 4, pp. 337-348, Oct.-Dec. 2003.

S-ar putea să vă placă și