Thứ Tư, 8 tháng 9, 2010

Cài đặt RPM trong linux

Trong Linux, phổ biến nhất là các gói cài đặt dạng RPM. Bản thân các gói RPM không chứa chương trình cài đặt, nó chỉ chứa các thông tin về các file sẽ được cài đặt, thông tin mô tả về phần mềm chứa trong gói và các file nằm trong gói RPM sẽ được cài đặt vào thư mục nào trong hệ thống. Các gói phần mềm dạng RPM được cài đặt vào hệ thống nhờ vào chương trình RPM có trong hệ thống.

Cách đơn giản nhất để cài một gói RPM, chẳng hạn gói foobar-1.0-1.i386.rpm là dùng lệnh:

rpm -i foobar-1.0-1.i386.rpm.

Để theo dõi quá trình install, bạn có thể thêm tham số:

rpm –ivh foobar-1.0-1.i386.rpm.

Để uninstall package đã được cài:

rpm -e foobar.

Nếu có một file RPM mà không biết nó là phần mềm nào, bạn có thể lấy thông tin bằng lệnh:

rpm -qpi koules-1.4-1.i386.rpm.

Nếu đã lỡ xóa một vài file nào đó và không chắc chắn rằng file đó đang còn cần thiết cho chương trình nào đó, bạn có thể xem thử hệ thống đang thiếu file cần thiết nào:

rpm –Va.

Thường khi cài một gói RPM nào đó, đòi hỏi phải cài thêm các gói phụ thuộc, bạn phải đi tìm và cài đặt các gói phụ thuộc trước khi cài được gói phần mềm trên. Hoặc cũng có thể gộp chung lại trên một dòng lệnh với lệnh RPM một danh sách các file RPM, được cách nhau bởi dấu khoảng trắng.

Trong Redhat hoặc Mandrake ở các phiên bản mới, Software Package Installation cũng tương tự như trình Add/Removed Software trong Windows vậy. Các tiện ích đi kèm trong bộ cài đặt được liệt kê đầy đủ theo từng nhóm để tiện theo dõi. Khi cài đặt một phần mềm, chương trình sẽ tự động kiểm tra các gói phụ thuộc và sẽ yêu cầu bạn đưa các CD cần thiết vào trong quá trình cài đặt.

Một kiểu cài đặt phần mềm phổ biến khác là bạn cài đặt từ các gói mã nguồn, thường được viết bằng ngôn ngữ C. Các gói này có dạng file nén *.TAR.GZ, *.BZ hoặc *.SRC.RPM. Trong trường hợp này, máy tính của bạn phải có sẵn các bộ công cụ biên dịch và các thư viện lập trình.

Sở dĩ phải có dạng TAR vì các file phải được gói lại thành một file trước khi nén thành GZ hoặc BZ, chứ không thể nén trực tiếp từ nhiều file thành một file nén được. Bản thân file *.TAR không phải là một file nén mà chỉ là một file chứa một tập các file khác gom lại mà thôi.

Với các gói nén bằng TAR.GZ, bạn bung nén như sau:

#tar xvzf file.tar.gz.

Sau khi giải nén, một thư mục chứa các file trong file nén được tạo ra. Bạn vào thư mục này và thực hiện quá trình biên dịch theo như file INSTALL hướng dẫn. Các bước thông thường (chứ không phải tất cả) là như sau:

#./configure; # make; #make install.

Bước chạy lệnh configure là để chương trình script xác lập cấu hình hệ thống cho việc biên dịch chương trình. Tùy vào cấu hình máy mà có chế độ biên dịch phù hợp và tối ưu cho chính hệ thống đó.

Lệnh make dùng để biên dịch mã nguồn thành file thực thi. Sau đó lệnh install để cài đặt file đã biên dịch lên hệ thống.

Thứ Ba, 7 tháng 9, 2010

Đề tài luận văn tốt nghiệp.

Mô phỏng và đánh giá giao thức định tuyến theo giải thuật XL trong mạng 802.11s

(simulator , analysis and evaluate algorithm XL for routing protocol in data link layer network for 802.11s standard protocol )
- Đọc tài liệu giải thuật XL
- Tìm hiểu về Ns-2,ns-3
- Xem chứng minh của XL
- Các tiêu chí đánh giá protocol

TT

Nội dung

Thời hạn

Ghi chú

1.

Học viên nộp Phiếu đăng ký đề tài LVThS (theo mẫu) tại phòng Đào tạo SĐH

06 → 10/09/2010

Kế hoạch này áp dụng chung cho tất cả các chuyên ngành (ngoại trừ chuyên ngành QTKD)

2.

Thời gian thực hiện đề cương

01/10 → 31/12/2010

3.

Tổ chức đánh giá đề cương LV

03/01 → 13/01/ 2011

4.

Thời gian thực hiện luận văn đợt 1 năm 2011

14/02 → 04/07/ 2011

Ajax PHP tutorial

Step 1 - Ajax basics


In this article I don't want to show you the history of AJAX and discuss its pros and cons, but only focus on how to create a basic working AJAX - PHP communication.

The only important thing at the moment is that AJAX uses JavaScript so it need to be enabled in your browser to successfully complete this tutorial.

To demonstrate the AJAX PHP connection we will create a very simple form with 2 input fields. In the first field you can type any text and we will send this text to our PHP script which will convert it to uppercase and sends it back to us. At the end we will put the result into the second input field. ( The example maybe not very useful but I think it is acceptable at this level. )

So let's list what we need to do:

* Listen on key-press event on the input field.
* In case of key-press send a message to the PHP script on the server.
* Process the input with PHP and send back the result.
* Capture the returning data and display it.

Our html code is very simple it looks like this:

Code:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Ajax - PHP example</title>
  6. </head>
  7. <form name="testForm">
  8. Input text: <input type="text" onkeyup="doWork();" name="inputText" id="inputText" />
  9. Output text: <input type="text" name="outputText" id="outputText" />
  10. </form>
  11. </body>
  12. </html>


As you can see there is a doWork() function which is called in every case when a key is up (a key was pressed). Of course you can use any other supported events if you want.

But what is this doWork() and how we can send messages to the server script? On the next page you will find the answers.

Step 2 - Sending data to PHP with Ajax


Before the explanation of the doWork() function we first need to learn a more important thing. To make a communication between the client and the server the client code needs to create a so called XMLHttpRequest object. This object will be responsible for AJAX PHP communication.

However creating this object is bit triky as the browser implement it various ways. If you don't want to support the quite old browsers we can do it as follows:

Code:
  1. // Get the HTTP Object
  2. function getHTTPObject(){
  3. if (window.ActiveXObject) 
  4. return new ActiveXObject("Microsoft.XMLHTTP");
  5. else if (window.XMLHttpRequest) 
  6. return new XMLHttpRequest();
  7. else {
  8. alert("Your browser does not support AJAX.");
  9. return null;
  10. }
  11. }


Ok, now we have the XMLHttpRequest object, so it's time to implement the business logic inside the doWork() function.

First of all we need to get a valid XMLHttpRequest object. If we have it then we can send the value of the inputText field to the server script. We do this by composing an URL with parameter, so in the PHP script we can use the $_GET super-global array to catch the data. As next step we call the send() function of the XMLHttpRequest object which will send our request to the server. At the moment our doWork() function looks like this:

Code:
  1. // Implement business logic
  2. function doWork(){
  3. httpObject = getHTTPObject();
  4. if (httpObject != null) {
  5. httpObject.open("GET", "upperCase.php?inputText="
  6. +document.getElementById('inputText').value, true);
  7. httpObject.send(null);

  8. }
  9. }


It's nice but how we can catch the response from the server? To do this we need to use an other special property of the XMLHttpRequest object. We can assign a function to this parameter and this function will be called if the state of the object was changed. The final code is the following:

Code:
  1. // Implement business logic
  2. function doWork(){
  3. httpObject = getHTTPObject();
  4. if (httpObject != null) {
  5. httpObject.open("GET", "upperCase.php?inputText="
  6. +document.getElementById('inputText').value, true);
  7. httpObject.send(null);
  8. httpObject.onreadystatechange = setOutput;
  9. }
  10. }


The last step on client side is to implement the setOutput() function which will change the value of our second field. The only interesting thing in this function that we need to check the actual state of the XMLHttpRequest object. We need to change the field value only if the state is complete. The readyState property can have the following values:

* 0 = uninitialized
* 1 = loading
* 2 = loaded
* 3 = interactive
* 4 = complete

So the setOutput() looks like this:

Code:
  1. // Change the value of the outputText field
  2. function setOutput(){
  3. if(httpObject.readyState == 4){
  4. document.getElementById('outputText').value
  5. = httpObject.responseText;
  6. }
  7.  
  8. }


Now the client side is ready let's implement the server side.

Step 3 - PHP code and the complete AJAX example


Implementing the server side functionality is very simple compared to the client side. In the PHP code we just need to check the $_GET super-global array. Afterwards convert it to uppercase and echo the result. So the PHP code is this:

Code:
  1. <?php
  2. if (isset($_GET['inputText']))
  3. echo strtoupper($_GET['inputText']);
  4. ?>


That's really short, isn't it?

At least you can find the complete client and server code below.

Client:

Code:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Ajax - PHP example</title>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <script language="javascript" type="text/javascript">
  12. <!--
  13. // Get the HTTP Object
  14. function getHTTPObject(){
  15. if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  16. else if (window.XMLHttpRequest) return new XMLHttpRequest();
  17. else {
  18. alert("Your browser does not support AJAX.");
  19. return null;
  20. }
  21. }
  22.  
  23. // Change the value of the outputText field
  24. function setOutput(){
  25. if(httpObject.readyState == 4){
  26. document.getElementById('outputText').value = httpObject.responseText;
  27. }
  28.  
  29. }
  30.  
  31. // Implement business logic
  32. function doWork(){
  33. httpObject = getHTTPObject();
  34. if (httpObject != null) {
  35. httpObject.open("GET", "upperCase.php?inputText="
  36. +document.getElementById('inputText').value, true);
  37. httpObject.send(null);
  38. httpObject.onreadystatechange = setOutput;
  39. }
  40. }
  41.  
  42. var httpObject = null;
  43.  
  44. //-->
  45. </script>
  46.  
  47. <form name="testForm">
  48. Input text: <input type="text" onkeyup="doWork();" name="inputText" id="inputText" />
  49. Output text: <input type="text" name="outputText" id="outputText" />
  50. </form>
  51. </body>
  52. </html>


Server:

Code:
  1. <?php
  2. if (isset($_GET['inputText']))
  3. echo strtoupper($_GET['inputText']);
  4. ?>