Application de mesure reseau pour iOS

De Ensiwiki
Révision de 8 juin 2011 à 21:36 par Guignous (discussion | contributions) (Traduction of command lines)

Aller à : navigation, rechercher

Application of networking measurment under iOS
Project Project of speciality 2A
Sub-project Networking
Students Antoine SPITAELS (TEL)



Promo 2012
Tutor Franck ROUSSEAU



The aim of this project is to develop an application for network performance measurement in real time enabling wireless mobility. IPMT is a tool initially implemented on Unix plateforms that is composed of two programs to send traffic respectively in TCP or in UDP, with given characteristics rate, burst size, delay between transmissions...), and two programs to receive data, compute and display every seconds statistics on the received traffic.

From a Posix plateform to iOS

Flags insertion

The application is initially implemented in C-language and functions under terminals of type Solaris, FreeBSD, MacOS X and Windows/Cygwin. The first step consists on adapting this application for iOS. As the language for developing applications for iPhone is Objective-C, so one possible solution is to code the application once more with Objectve-C. Yet, this will require much time and effort. Fortunately, libraries are well recognized under iOS as C is a sub-layer of Objective C. It would be sufficient then to modify the original code to adapt it for iOS. Using flags such as #ifdef __FreeBSD_, #ifdef __APPLE_ enables you to force the compiler to compile or not certain piece of code. First of all, you will need to include the following header "TargetConditionals.h" for Apple plateforms as shown below:

#ifdef __APPLE__ 
#include "TargetConditionals.h" 

Let's consider the following exemple:

   return 0; 

It this example, the application will quit when executed on Unix OS: exit(0) abd the command line will be given back to the user. This won't happen once under iOS, then the user will always be connected to the aplication on iPhone unless he quit.

Management of executables

If your application is implemented on a Posix plateform then it might include many executables which are linked within a Makefile. For iPhone, only one executable is allowed. Then, to adapt your application to iOS one poosible solution is to replace each main by a function while coding for iPhone. Only one main should be left.

function(int argc,char **argv)
main(int argc,char **argv)

Modifications under iOS

  1. Functions reset

<< int getopt(int, char * const [], const char *) >> "getopt" is a function that analyses the arguments of the command line. The first argument "int" indicates the number of elements of the table "char*[] " containing arguments transmitted to the main(). An option is preceded by "-". "optind" is a variable which indicates the next element to be analyzed in the char*[]. The system set the value of this variable to 1. Under iOS, to be able to analyze the same table of strings many times ie each time we launch a request, we have to reset "getopt" by setting the value of "optind" to 1. This will force a routine of reset to be executed.

   while ((ch = getopt(argc, argv, "abdegHhi:jM:m:r:o:p:t:vk46q")) != -1)

You can get further information on this issue on this page [1]

  1. Creating threads

The application is launched on iOS in a new thread which is liberated when we quit the application. This enables multitasking on iPhone.

Graphical interface

Adaptation of command lines

Under a Posix plateform the application is launched thanks to command lines indicated in a terminal. This method is not possible under iPhone as there is no terminal or another way to access to the network layer, and especially it is not very convenient. We have to pass through the Cocoa layer to have access to the Core Services layer. A graphical user interface (GUI) is necessary to act as the intermediary between the user and the source code. Interface Builder is the tool to implement the interface which is coded in Objective-C. To be able to get the equivalent of command lines under the interface, we have to implement Outlets ( buttons for example) and then connect them to the appropriate objects. The next step consists on defining the actions into functions, that is the moment for your functions implemented in C-language. The messages returned by the application are sent to Outlets of type "UITextView"... To enable showing packets in real time, a timer is set and fired every 0,5s to call a method which updates the appropriate fields.

Manipulating iPhone keyboard

When it comes to insert a text in a "UITextView" the keyboard is always on the screen which hamper the user to insert other fields below. This pushed us to add a button to the keyboard which makes the keyboard disappear.

- (void)addButtonToKeyboard {
	// create custom button
	doneButton.frame = CGRectMake(0, 163, 106, 53);
	doneButton.adjustsImageWhenHighlighted = NO;
	if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0) {
		[doneButton setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
		[doneButton setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
 	} else {        
		[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
		[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
	[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
	// locate keyboard view
	UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
	UIView* keyboard;
	for(int i=0; i<[tempWindow.subviews count]; i++) {
		keyboard = [tempWindow.subviews objectAtIndex:i];
		// keyboard found, add the button
		if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
			if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
				[keyboard addSubview:doneButton];
		} else {
	 		if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
  				[keyboard addSubview:doneButton];

Graphic plotting

CorePlot is a plotting framework that enables creating graphs in an iPhone application. There are many versions of CorePlot. In our case, we have chosen the recent one available on Google Code [2]. To install this framework on Xcode 4, you have to follow these instructions:

  1. Copy the CorePlotHeaders directory to your Xcode project (this file figures in iOS Binaries file).
  2. Copy the Frameworks file to your Xcode project (this file figures in Source Code).
  3. Open your apps Target Build Settings, and for Other Linker Flags include this: -ObjC -all_load
  4. Add the QuartzCore framework to the project.

This is the static method for installing the framewok. Thus, you are not supposed to re-install CorePlot each time you change the device in order to test the application. All the previous configuration will figure on you GIT deposit. Finally, you should import the following header "CorePlot-CocoaTouch.h" in the appropriate files to be able to call classes of CorePlot.