a distributed csma algorithm for throughput and utility maximization in wireless networks1
Post on 28-Jul-2015
310 Views
Preview:
TRANSCRIPT
A Distributed CSMA Algorithm for Throughput and Utility Maximization in Wireless Networks
Abstract:
In multihop wireless networks, designing distributed scheduling algorithms to achieve the maximal throughput is a challenging problem because of the complex interference constraintsamong different links. Traditional maximal-weight scheduling (MWS), although throughput-optimal, is difficult to implement in distributed networks. On the other hand, a distributed greedy protocol similar to IEEE 802.11 does not guarantee the maximal throughput. In this paper, we introduce an adaptive carrier sense multiple access (CSMA) scheduling algorithm that can achieve the maximal throughput distributively. Some of the major advantages of the algorithm are that it applies to a very general interference model and that it is simple, distributed, and asynchronous. Furthermore, the algorithm is combined with congestion control to achieve the optimal utility and fairness of competing flows. Simulations verify the effectiveness of the algorithm. Also, the adaptive CSMA scheduling is a modular MAC-layer algorithm that can be combined with various protocols in the transport layer and network layer. Finally, the paper explores some implementation issues in the setting of 802.11 networks.
INTRODUCTION:
In multihop wireless networks, it is important to efficiently utilize the network resources and provide fairness to competing data flows. These objectives require the cooperation of different network layers. The transport layer needs to inject the right amount of traffic into the network based on the congestion level, and theMAC layer needs to serve the traffic efficiently to achieve high throughput. Through a utility optimization framework [1], this problem can be naturally decomposed into congestion control at the transport layer and scheduling at the MAC layer. It turns out that MAC-layer scheduling is the bottleneck of the problem [1]. In particular, it is not easy to achieve the maximal throughput through distributed scheduling, which in turn prevents full utilization of the wireless network. Scheduling is challenging since the conflicting relationships between different links can be complicated It is well known that maximal-weight scheduling (MWS) [22] is throughput-optimal. That is, that scheduling can support any incoming rates within the capacity region. In MWS, time is assumed to be slotted. In each slot, a set of nonconflicting links (called an “independent set,” or “IS”) that have the maximal weight are scheduled, where the “weight” of a set of links is the summation of their queue lengths. (This algorithm has also been applied to achieve 100% throughput in input-queued switches [23].) However, finding such a maximal-weighted IS is NP-complete in general and is hard even for centralized algorithms. Therefore, its distributed implementation is not trivial in wireless networks. A few recent works proposed throughput-optimal
algorithms for certain interference models. For example, Eryilmaz et al. [3] proposed a polynomial-complexity algorithm for the “two-hop interference model”.1 Modiano et al. [4] introduced a gossip algorithm for the “node-exclusive model”.2 The extensions to more general interference models, as discussed in [3] and [4],involve extra challenges. Sanghavi et al. [5] introduced an algorithm that can approach the throughput capacity (with increasing overhead) for the node-exclusive model.On the other hand, a number of low-complexity but suboptimal scheduling algorithms have been proposed in the literature. By using a distributed greedy protocol similar to IEEE 802.11, [8] shows that only a fraction of the throughput region can be achieved (after ignoring collisions). The fraction depends on the network topology and interference relationships. The algorithm is related to Maximal Scheduling [9], which chooses a maximal schedule among the nonempty queues in each slot. Different from Maximal Scheduling, the Longest-Queue-First (LQF) algorithm [10]–[13] takes into account the queue lengths of the nonempty queues. It shows good throughput performance in simulations. In fact, LQF is proven to be throughput-optimal if the network topology satisfies a “local pooling” condition [10], [12] or if the network is small [13]. In general topologies, however, LQF is not throughput-optimal, and the achievable fraction of the capacity region can be characterized as in [11]. Reference [14] studied the impact of such imperfect scheduling on utility maximization in wireless networks. In [16], Proutiere et al. developed asynchronous random-access-based scheduling algorithms that can achieve throughput performance similar to that of the Maximum Size scheduling algorithm. Our first contribution in this paper is to introduce a distributed adaptive carrier sense multiple access (CSMA) algorithm for a general interference model. It is inspired by CSMA, but may be applied to more general resource sharing problems (i.e., not limited to wireless networks). We show that if packet collisions are ignored (as in some of the mentioned references), the algorithm can achieve maximal throughput. The optimality in the presence of collisions is studied in [30] and [31] (and also in [35] with a different algorithm). The algorithm may not be directly comparable to those throughput-optimal algorithms we have mentioned since it utilizes the carrier-sensing capability. However, it does have a few distinct features: • Each node only uses its local information (e.g., its backlog). No explicit control messages are required among the nodes. • It is based on CSMA random access, which is similar to the IEEE 802.11 protocol and is easy to implement. • Time is not divided into synchronous slots. Thus, no synchronization of transmissions is needed.
EXISTING SYSTEM:
A few recent works proposed throughput-optimal algorithms for certain interference models
Each node only uses its local information (e.g., its backlog). No explicit control messages are required among the nodes.
It is based on CSMA random access, which is similar to the IEEE 802.11 protocol and is easy to implement.
Time is not divided into synchronous slots. Thus, no synchronization of transmissions is needed.
PROPOSED SYSTEM:
Efficiently utilize the network resources and provide fairness to competing
data flows.
By sensing time to not zero, the back off time is usually chosen to be a
multiple of mini-slots, where each mini-slot cannot be arbitrarily small.
we have combined that algorithm with congestion control to approach the maximal utility and showed the connection with back-pressure scheduling
Reducing the queuing delay
Approaching the Maximal Utility
Joint CSMA Scheduling and Congestion Control
SYSTEM SPECIFICATION:
HARDWARE SPECIFICATION:
Processor : Intel Pentium-IV
Speed : 1.1GHz
RAM : 512MB
Hard Disk : 40GB
General : Key Board, Monitor , Mouse
SOFTWARE SPECIFICATION:
Operating System : Windows XP
Front-end : Visual C# .Net.
Back-end : SQL-Server
MODULE DESCIRPTION
Interference Model:
First, we describe the general interference model we will consider in this paper. Assume there are K links in the network, where each link is an (ordered) transmitter–receiver pair. The network is associated with a conflict graph (or “CG”) , where is the set of vertices (each of them represents a link) and is the set of edges. Two links cannot transmit at the same time (i.e., “conflict”) iff there is an edge between them. Note that this framework includes the “node-exclusive model” and “two-hop interference model” mentioned as two special cases.Assume that has independent sets (“IS,” not confined to “maximal independent sets”). Denote the th IS by a vector . The th element of , if link is transmittingin the IS, and otherwise. We also refer to as a transmission state, and as the transmission state of link .
An Idealized CSMA Protocol and the Average Throughput
We use an idealized model of CSMA as in [25]–[27]. This model makes two simplifying assumptions. First, it assumes that if two links conflict, because their simultaneous transmissions would result in incorrectly received packets, then each of the two links hears when the other one transmits. Second, the modelassumes that this sensing is instantaneous. Consequently, collisions can be avoided, as we will further explain. The first assumption implies that there are no hidden nodes (HN). This is possible if the range of carrier-sensing is large enough [29].3 The second assumption is violated in actual systems because ofthe finite speed of light and of the time needed to detect a received power. Since the detailed balance equations hold, the CSMA Markov chain is time-reversible. In fact, the Markov chain is a reversible “spatial process,” and its stationary distribution (1) is a Markov random field ([24, p. 189]; [28]). (That is, the state of every link is conditionally independent of all other links, given the transmission states of its conflicting links.)
Discussion
It has been believed that optimal scheduling is NP-complete in general. This complexity is reflected in the mixing time of the CSMA Markov chain (i.e., the time for the Markov chain to approach its stationary distribution). In [38], the upper bound used to quantify the mixing time is exponential in . However, the bound may not be tight in typical wireless networks. For example, in a network where all links conflict, the CSMA Markov chain mixes much faster than the bound. 2) There is some resemblance between the above algorithm (in particular the CSMA Markov chain) and simulated annealing (SA) [20]. SA is an optimization technique that utilizes time-reversible Markov chains to find a maximum of a function. SA can be used, for example, to find the maximal-weighted IS (MWIS)
that is needed in Maximal-Weight Scheduling. However, note that our algorithm does not try to find the MWIS via SA. Instead
DATA FLOW DIAGRAM:
CSMA Algorithm:
SERVER
SourceDestinatio
nRouter
CLIENT
Time Allocation
CSMA
Algorithm
Flow rates
Login
Authenticated
Peer1
Peer2
peer3
Client
Data Flow for time constrain
Server
Request
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 exposing the problems that
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 : identified classes of valid input must be accepted.
Invalid Input : identified classes of invalid input must be rejected.
Functions : identified functions must be exercised.
Output : identified classes of application outputs must be
exercised.
Systems/Procedures: interfacing systems or procedures must be invoked.
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.
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.
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. There’s
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 you’re 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 doesn’t 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 doesn’t attempt to access memory that hasn’t 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 Microsoft’s 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 Microsoft’s new language. It’s 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 Java-language 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 State’s Perl Dev Kit.
Other languages for which .NET compilers are available include
FORTRAN
COBOL
Eiffel
Fig1 .Net Framework
ASP.NET
XML WEB
SERVICES
Windows
Forms
Base Class Libraries
Common Language Runtime
Operating System
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 Try…Catch…Finally
statements to create exception handlers. Using Try…Catch…Finally 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; if (FTServerCode2.colc21 == null) { FTServerCode2.timedelay[0] += FTServerCode2.tcalc; lblc21.BackColor = Color.Blue;
} if (FTServerCode2.colc22 == null) { FTServerCode2.timedelay[1] += FTServerCode2.tcalc; lblc22.BackColor = Color.Blue; } lblc23.BackColor = Color.LimeGreen; // ac3 = "y"; } else if (FTServerCode2.filefrm2 == "3") { FTServerCode2.timedelay[3] += FTServerCode2.tcalc; if (FTServerCode2.colc21 == null) { FTServerCode2.timedelay[0] += FTServerCode2.tcalc; lblc21.BackColor = Color.Blue; } if (FTServerCode2.colc22 == null) { FTServerCode2.timedelay[1] += FTServerCode2.tcalc;
lblc22.BackColor = Color.Blue; } if (FTServerCode2.colc23 == null) { FTServerCode2.timedelay[3] += FTServerCode2.tcalc; lblc23.BackColor = Color.Blue; } lblc24.BackColor = Color.LimeGreen; //ac4 = "y"; } else if (FTServerCode2.filefrm2 == "4") { FTServerCode2.timedelay[4] += FTServerCode2.tcalc; if (FTServerCode2.colc21 == null) { FTServerCode2.timedelay[0] += FTServerCode2.tcalc; lblc21.BackColor = Color.Blue; } if (FTServerCode2.colc22 == null) { FTServerCode2.timedelay[1] += FTServerCode2.tcalc; lblc22.BackColor = Color.Blue; } if (FTServerCode2.colc23 == null) {
FTServerCode2.timedelay[3] += FTServerCode2.tcalc;
lblc23.BackColor = Color.Blue; } if (FTServerCode2.colc24 == null) { FTServerCode2.timedelay[4] += FTServerCode2.tcalc; lblc24.BackColor = Color.Blue; } lblc25.BackColor = Color.LimeGreen; //ac5 = "y"; } else if (FTServerCode2.filefrm2 == "5") { FTServerCode2.timedelay[5] += FTServerCode2.tcalc;
lblc26.BackColor = Color.LimeGreen; // ac6 = "y"; } else if (FTServerCode2.filefrm2 == "6") { FTServerCode2.timedelay[6] += FTServerCode2.tcalc;
if (FTServerCode2.colc26 == null) { FTServerCode2.timedelay[6] += FTServerCode2.tcalc; lblc26.BackColor = Color.Blue; } lblc27.BackColor = Color.LimeGreen; //ac7 = "y"; } else if (FTServerCode2.filefrm2 == "7") { FTServerCode2.timedelay[7] += FTServerCode2.tcalc; if (FTServerCode2.colc26 == null) { FTServerCode2.timedelay[6] += FTServerCode2.tcalc; lblc26.BackColor = Color.Blue; } if (FTServerCode2.colc27 == null) { FTServerCode2.timedelay[7] += FTServerCode2.tcalc; lblc27.BackColor = Color.Blue; } lblc28.BackColor = Color.LimeGreen; //ac8 = "y";
} else if (FTServerCode2.filefrm2 == "8") { FTServerCode2.timedelay[8] += FTServerCode2.tcalc; if (FTServerCode2.colc26 == null) { FTServerCode2.timedelay[6] += FTServerCode2.tcalc; lblc26.BackColor = Color.Blue; } if (FTServerCode2.colc27 == null) { FTServerCode2.timedelay[7] += FTServerCode2.tcalc;
lblc27.BackColor = Color.Blue; } if (FTServerCode2.colc28 == null) { FTServerCode2.timedelay[8] += FTServerCode2.tcalc; lblc28.BackColor = Color.Blue; } lblc29.BackColor = Color.LimeGreen; //ac9 = "y"; } else if (FTServerCode2.filefrm2 == "9") { FTServerCode2.timedelay[9] += FTServerCode2.tcalc; if (FTServerCode2.colc26 == null) { FTServerCode2.timedelay[6] += FTServerCode2.tcalc; lblc26.BackColor = Color.Blue; } if (FTServerCode2.colc27 == null) { FTServerCode2.timedelay[7] += FTServerCode2.tcalc; lblc27.BackColor = Color.Blue; } if (FTServerCode2.colc28 == null) { FTServerCode2.timedelay[8] += FTServerCode2.tcalc; lblc28.BackColor = Color.Blue; } if (FTServerCode2.colc29 == null) { FTServerCode2.timedelay[9] += FTServerCode2.tcalc;
lblc29.BackColor = Color.Blue;
} lblc210.BackColor = Color.LimeGreen; //ac10 = "y"; }
}
private void timer3_Tick(object sender, EventArgs e) { if (FTServerCode3.filefrm3 == "0") { FTServerCode3.timedelay[0] += FTServerCode3.tcalc; lblc31.BackColor = Color.LimeGreen; //ac1 = "y"; } else if (FTServerCode3.filefrm3 == "1") { FTServerCode3.timedelay[1] += FTServerCode3.tcalc; if (FTServerCode3.colc31 == null) { FTServerCode3.timedelay[0] += FTServerCode3.tcalc; lblc31.BackColor = Color.Blue; }
lblc32.BackColor = Color.LimeGreen; // ac2 = "y"; } else if (FTServerCode3.filefrm3 == "2") { FTServerCode3.timedelay[2] += FTServerCode3.tcalc; if (FTServerCode3.colc31 == null) { FTServerCode3.timedelay[0] += FTServerCode3.tcalc;
lblc31.BackColor = Color.Blue; } if (FTServerCode3.colc32 == null) { FTServerCode3.timedelay[1] += FTServerCode3.tcalc;
lblc32.BackColor = Color.Blue; } lblc33.BackColor = Color.LimeGreen; // ac3 = "y"; } else if (FTServerCode3.filefrm3 == "3")
{ FTServerCode3.timedelay[3] += FTServerCode3.tcalc; if (FTServerCode3.colc31 == null) { FTServerCode3.timedelay[0] += FTServerCode3.tcalc; lblc31.BackColor = Color.Blue; } if (FTServerCode3.colc32 == null) { FTServerCode3.timedelay[1] += FTServerCode3.tcalc; lblc32.BackColor = Color.Blue; } if (FTServerCode3.colc33 == null) { FTServerCode3.timedelay[2] += FTServerCode3.tcalc; lblc33.BackColor = Color.Blue; } lblc34.BackColor = Color.LimeGreen; //ac4 = "y"; } else if (FTServerCode3.filefrm3 == "4") { FTServerCode3.timedelay[4] += FTServerCode3.tcalc; if (FTServerCode3.colc31 == null) { FTServerCode3.timedelay[0] += FTServerCode3.tcalc; lblc31.BackColor = Color.Blue; } if (FTServerCode3.colc32 == null) { FTServerCode3.timedelay[1] += FTServerCode3.tcalc;
lblc32.BackColor = Color.Blue; } if (FTServerCode3.colc33 == null) { FTServerCode3.timedelay[2] += FTServerCode3.tcalc; lblc33.BackColor = Color.Blue; } if (FTServerCode3.colc34 == null) { FTServerCode3.timedelay[3] += FTServerCode3.tcalc; lblc34.BackColor = Color.Blue; } lblc35.BackColor = Color.LimeGreen; //ac5 = "y";
} else if (FTServerCode3.filefrm3 == "5") { FTServerCode3.timedelay[5] += FTServerCode3.tcalc; lblc36.BackColor = Color.LimeGreen; // ac6 = "y"; } else if (FTServerCode3.filefrm3 == "6") { FTServerCode3.timedelay[6] += FTServerCode3.tcalc;
if (FTServerCode3.colc36 == null) { FTServerCode3.timedelay[6] += FTServerCode3.tcalc; lblc36.BackColor = Color.Blue; } lblc37.BackColor = Color.LimeGreen; //ac7 = "y"; } else if (FTServerCode3.filefrm3 == "7") { FTServerCode3.timedelay[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); string fileName = Encoding.ASCII.GetString(write, 4, fileNameLen);
BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + "/SYS2/" + 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], 8); 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 3
class FTServerCode3{ 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 filefrm3; public static string destip;
string akc; double tstart; double tend; public FTServerCode3() { IPHostEntry ipEntry = Dns.GetHostEntry(Environment.MachineName); IPAddress IpAddr = ipEntry.AddressList[0]; ipEnd = new IPEndPoint(IpAddr, 9); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); sock.Bind(ipEnd); } public static string receivedPath; public static string curMsg = "Stopped"; public static string colc31; public static string colc32; public static string colc33; public static string colc34; public static string colc35; public static string colc36; public static string colc37; public static string colc38; public static string colc39; public static string colc310; 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..."; filefrm3 = Encoding.ASCII.GetString(clientData, 0, 1);
if (filefrm3 == "0") { colc31 = "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 (filefrm3 == "1") { colc32 = "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 (filefrm3 == "2") { colc33 = "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 (filefrm3 == "3") { colc34 = "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 (filefrm3 == "4") { colc35 = "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 (filefrm3 == "5") { colc36 = "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 (filefrm3 == "6") { colc37 = "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 (filefrm3 == "7") { colc38 = "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 (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; } }
CONCLUSION:
In this paper, we have proposed a distributed CSMA scheduling algorithm and showed that, under the idealized CSMA, it is throughput-optimal in wireless networks with a general interference model. We have utilized the product-form stationary distribution of CSMA networks in order to obtain the distributed algorithm and the maximal throughput. Furthermore, we have combined that algorithm with congestion control to approach
the maximal utility and showed the connection with back-pressure scheduling. The algorithm is easy to implement, and the simulation results are encouraging. The adaptive CSMA algorithm is a modularMAC-layer component that can work with other algorithms in the transport layer and network layer. In [40], for example, it is combined with optimal routing, anycast, and multicast with network coding. We also considered some practical issues when implementing the algorithm in an 802.11 setting. Since collisions occur in actual 802.11 networks, we discussed a few recent algorithms thatexplicitly consider collisions and can still approach throughputoptimality. Our current performance analysis of Algorithms 1–3 is based on a separation of time scales, i.e., the vector is adapted slowly to allow the CSMA Markov chain to closely track the stationarydistribution . The simulations, however, indicate that suchslow adaptations are not always necessary. In the future, we are interested to understand more about the case without time-scale separation.
top related