2014年3月30日 星期日

防火牆技術

穿越防火牆技術

1. (穿越防火牆技術) http://www.cs.nccu.edu.tw/~lien/Writing/NGN/firewall.htm
2. Libnice (http://nice.freedesktop.org/wiki/)
3. PJNATH - Open Source ICE, STUN, and TURN Library (http://www.pjsip.org/pjnath/docs/html/index.htm)
4. The TCP/IP guide (http://www.tcpipguide.com/free/t_IPNetworkAddressTranslationNATProtocol.htm)
5.NAT Traversal and Peer to Peer (http://lab.howie.tw/2012/07/Peer-to-Peer-and-NAT-Traversal.html)
6.



Code Reference
1. Google libjingle (https://developers.google.com/talk/libjingle/?hl=zh-TW&csw=1)
2. STUNT (http://nutss.gforge.cis.cornell.edu/jstunt-examples.php)
3. PJNATH (http://www.pjsip.org/pjnath/docs/html/index.htm)

Difference Between NAT and Proxy

Source: http://www.differencebetween.com/difference-between-nat-and-vs-proxy/

NAT vs Proxy 
Network Address Translation (NAT) is the process that modifies the IP address in a header of an IP packet, while it is travelling through a routing device. NAT allows one set of IP addresses to be used for traffic within a LAN (Local Area Network) and another set of IP addresses for outside traffic. One to one transformation of IP addresses are provided by the simplest form of NAT. Proxy (proxy server) is a server that is located between a client (who is looking for a resource) and some other server and acts as a mediator. The client requesting the resource connects to the proxy server and the proxy evaluates the request based on its filtering rules.

What is NAT?
NAT modifies IP address in a header of an IP packet, while it is travelling through a routing device. NAT allows one set of IP addresses to be used for traffic within a LAN and another set of IP addresses for outside traffic. One to one transformation of IP addresses are provided by the simplest form of NAT. NAT has several advantages. It improves the security of a LAN since it provides the option to hide internal IP addresses. Furthermore, as the IP addresses are only used internally, it will not cause any conflicts with IP addresses used in other organizations. Also, using a single internet connection for all the computers in a LAN is made possible by NAT. NAT works with the use of a NAT box, which is situated in the interface where the LAN is connected to the internet. It contains a set of valid IP addresses and it is responsible for performing the IP address translations.

What is a Proxy?
Proxy is a server that is located between a client (that is looking for a resource) and some other server and acts as a mediator. The client requesting the resource connects to the proxy server and the proxy evaluates the request based on its filtering rules. If the request is validated, proxy connects to the server and provides the requested resource to the client. On the other hand, proxy may satisfy the client’s request without going to the specified server. For this, the proxy uses a cache and any of the subsequent requests for the same resource are satisfied without contacting the specified server. Due to this, proxies can improve the performance greatly. Furthermore, proxies can be used to filter requests and prevent accessing some web sites.

What is the difference between NAT and Proxy?
NAT modifies IP address in a header of an IP packet, while it is travelling through a routing device and allows to use a different set of IP addresses for traffic within a LAN than the set of IP addresses for outside traffic, while a proxy is a server that is located between a client and some other server and acts as a mediator. NAT does not need any special application software to operate, whereas applications behind a proxy server must support proxy services and should be configured to use the proxy server.


Read more: http://www.differencebetween.com/difference-between-nat-and-vs-proxy/#ixzz2xVQ3TG5i

2014年1月27日 星期一

Ubuntu 遠端桌面畫面問題

Source:http://blog.snowtec.org/2009/05/ubuntu-904-vnc-problem/

Ubuntu內建了遠端桌面功能 (也就是VNC Server),在「系統→偏好設定→遠端桌面」可以進行開啟與其他設定。
不過最近我遇到了一個相當奇怪的Bug…連線成功之後,系統卻不會將畫面更新,總是停留在第一個畫格。雖然動作事件都有送到被控端,但在看不到螢幕反應的情況下使用上實在是有點…不,是十分困難啊!遇到這種事情當然我們還是要求助於Google大神,然後很幸運的我得到了解答。
這個Bug的發生時機是,你使用nVidia的顯示卡,然後也啟用了Compiz (也就是桌面特效)。Xwindow有個功能叫XDamage,在做VNC連線時可以只傳送桌面上改變的部份的畫面 (例如,你移動的視窗),進而減少使用網路傳輸量。但不知為什麼,遇到受限制的nVidia驅動程式加上Compiz,這個功能就會壞掉,變成client一旦連上之後畫面就不會更新,永遠卡在第一個frame。
在 Launchpad 已經有網友提出這個bug,也已經有解決辦法了。
解決方案有:
  1. 不使用VNC。 (這…)
  2. 完全關閉桌面特效。
    ubuntu桌面特效
  3. 使用別的VNC軟體,例如:x11vnc:
    $ sudo apt-get install x11vnc
    $ x11vnc –noxdamage –passwd 密碼 -forever
  4. 安裝修正包:
    Launchpad上已經放出了修正過後的Vino (內建的VNC Server),到 這裡 可以下載更新過後的版本。
    安裝完畢之後,按「Alt+F2」執行「gconf-editor」,把鍵值
    「/desktop/gnome/remote_access/disable_xdamage」修改為true (勾起來的意思),再到選單中啟動遠端桌面。
    gconfeditor遠端連線修改
雖然說這樣會影響連線品質,不過目前似乎是沒有更好的解法,我也不敢保證我的是最好最恰當的解法,所以如果有什麼意見的話也歡迎留言跟我說。
到這裡你的VNC應該就可以順利、快樂、至少不會停格的連線了。

2014年1月5日 星期日

3C應用

1. 你的手機就是最高檔的行車記錄器

2. 只是手寫何必買 Wacom?手機免費變身無線手寫板!
3. 將#可穿戴設備#與汽車駕駛結合起來,現代汽車正開發一款#Google Glass#應用來操控汽車
4. HTC Mini+ – 超越配件等級的多功能智慧小手機
7. 輕便旅行隨身好物 i-FlashDrive雙頭龍Android特別版
8. Smart Sign Language Interpreter智慧型手語翻譯 聽障人士代言人
9. 2014 CES 大預測:別管 Google Glass 了,穿戴式科技大舉入侵健康照護和健身領域!
10. Google再次聚焦家庭能源使用的追踪,正在測試連接到網絡的智能恆溫器
11. 想讓傳統家電變智能?只需配一個智能插座就行!Plugaway 推智能插座及智能LED燈

2013年12月19日 星期四

為甚麼Java提供Interface

Source: http://programming.im.ncnu.edu.tw/J_Chapter7.htm

為甚麼Java提供Interface

雖然程式語言提供了基本資料型別,但由於各種應用都有其特定的資料結構需求,因此程式語言都提供使用者自訂型別的能力。型別自訂後,其使用的方法和基本資料型態類似。Class就是一種使用者自定的型別。Java提供了instanceof的保留字,用以判斷某reference所指到的物件,其型態和某Class是否相容:
Object ref;
ref = new Bird();
if (ref instanceof Animal) { // correct
    System.out.println("ref is currently pointing to an Animal Object.");
}
在物件導向的觀念裡,物件可以具有多個型別。例如「附有橡皮擦的鉛筆」,可以當成是「書寫工具」,也可以當成是「擦拭工具」。物件可有多種型別的觀念,不僅在日常生活中常見,在軟體開發上也有實際的需求。要使物件具有多種型別,可透過繼承來達成。例如Bird物件就同時具有Bird和Animal兩種型別。由於Java的Class只能有單一繼承,因此像「附有橡皮擦的鉛筆」同時具有「書寫工具」和「擦拭工具」兩種互不相關的型別,就無法透過Class的單一繼承來達成了。
許多語言提供Class的多重繼承,但Java考量諸如下面的多重繼承問題,選擇不引進Class多重繼承:
假設B繼承A,C繼承A,D又多重繼承B,C, 該語言又使用virtual function則
  • 如果B, C都有overwrite A的methodM方法, 而A ref指到D類別的物件, 請問透過ref傳遞methodM訊息時, 應該使用B還是C的methodM?
在不引進Class多重繼承的前提下,為了讓物件具有多種型態,Java提供了Interface(界面)的觀念。Interface可視為沒有實作的自訂型別,和Class用來作為Object的模板,有所不同。Class可以宣告實作多個Interface,而Interface之間可以有多重繼承。

Java有關Interface的語法

  • 宣告Interface
    public interface Listener {
        double PI = 3.14149; // 同public static final
        void listen(); // 同public abstract
    }
    public interface Runnalbe {
        int PERIOD = 10;
        void run();
    }
    public interface AnotherRun {
        int PERIOD = 20;
        void run();
        int run(int);
    }
    
    注意上述函數宣告沒有{},也就是說沒有實作的意思。
  • Interface的繼承
    public interface ActionListener extends Listener {
    }
    public interface MultiInterface extends Listener, Runnalbe {
    }
    
  • Class實作Interface的宣告
    public class A implements Listener {
        public void listen() {
        }
    }
    public class B implements Listener, Runnable {
        public void listen() {
        }
        public void run() {
        }
    }
    public class C implements MultiInterface {
        public void listen() {
        }
        public void run() {
        }
    }
    public class D extends A implements Runnable, AnotherRun {
        public void run() {
        }
        public int run(int period) {
        }
    }
    
Interface如同Class一樣可以作為一種型態的宣告,因此如下的判斷都是正確的
D ref = new D();
ref instanceof D; // true
ref instanceof Runnable; // true
ref instanceof AnotherRun; // true
ref instanceof A; // true
ref instanceof Listener; // true
Interface中宣告的變數具有以下特質
  • public。所謂Interface(界面)指的是外界觀看某物件時,所能看到的表象以及溝通的管道,因此Interface內的成員一定是public。也就是說即便宣告時沒寫public關鍵字,Compiler也會幫我們加上去。
  • static。既然Interface沒有實作,就不可能透過Interface產生物件。換言之,Interface內的變數一定是屬於Class,而不屬於Object。
  • final。Interface可視為一種約定或契約,我們自然不希望裡面的variable可以隨便更改。
Interface中宣告的method具有以下特質
  • public。同變數說明。
  • abstract。Interface沒有實作,裡面定義的method只是宣告而已。沒有實作的method,在Java裡用abstract這個關鍵字來表達。有關abstract的詳細說明,請見下一節
當Interface繼承多個Interface,或Class實作多個Interface時,如果有多個同名的函數或變數時,應該如何處理? 例如Runnable和AnotherRun這兩個界面都定義了變數PERIOD和方法run。
  • 相同變數名稱:由於interface內的變數具有static的性質,因此使用這些變數時,必須加上Interface的名稱才行,如Runnable.PERIOD,AnotherRun.PERIOD,因此不會造成任何混淆。
  • 相同函數名稱:如果signature(參數個數,型態以及傳回值型態)完全相同,則Class只要實作一次即可,例如Runnable和AnotherRun均定義void run(),因此Class D只要實作一次就好了。如果同名函數符合Overloading,把它們分別當成不同的method即可。如果參數完全相同,但傳回值不同,則違反了Overloading的原則,會產生Compile Error。

Abstract Class and Method

只有參數宣告,沒有實作的方法,稱為abstract method。某些情況下,雖然有實作,但我們希望強迫子類別必須override該方法時,也可以宣告為abstract method。Interface裡的方法一定沒有實作,因此必然為abstract method。
如果Class裡有一個以上的abstract method,則該class必須宣告為abstract。有時候即使沒有abstract method,也可以宣告該class為abstract。我們不可以直接new該class的物件,只能new其子類別物件。
public abstract class AbstractExample {
    int x;
    public void abstract abstractMethod() {
    }
    public AbstractExample() {
        x = 5;
    }
}
public class SubClass extends AbstractExample {
    public void abstractMethod() { // must override this method, or SubClass be declared as abstract class
        x = 10;
    }
}
public class Main {
    public static void main(String[] argv) {
        AbstractExample a = new SubClass(); // correct
        a.abstractMethod(); // virtual function, call SubClass's abstractMethod
        a = new AbstractExample(); // Compile error, you can't new abstract class
    }
}
綜合以上所述,可列出以下幾點特徵
  • 具有abstract method的class必須宣告為abstract class。
  • 繼承abstract class的子類別必須override所有父類別的abstract method,否則子類別也必須宣告為abstract class。
  • 實作Interface A的Class必須實作A裡的所有method,否則必須宣告自己為abstract class。
  • 不能直接new abstract class,只能new其非abstract class的子類別。

2013年10月30日 星期三

如何自动cradle wince模拟器

http://m.blog.csdn.net/blog/chief1985/5429861#

wince的模拟器有个Device Emulator Manager,这里面可以对模拟器进行cradle,之后Device Emulator Manager会是activesync和模拟器建立连接(DMA方式),之后wince的一些工具就可以用了。例如cecopy.exe,cedir.exe等,下面是一个列表:
cecopy.exe:拷贝文件到wince设备或模拟器(反过来也可以)
cedel.exe:删除wince设备或模拟器上的文件
cedir.exe:列举文件
ceexec.exe:执行程序
cegetinfo.exe:获取剩余空间信息
cemkdir.exe:创建目录
cereg.exe:注册表操作
这些工具的意义看名字就知道了,可以在http://www.microsoft.com/downloads/details.aspx?familyid=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en下载,这里面还有一些别的工具。
cradle一般的做法是Device Emulator Manager右键来选择。对于喜欢命令行一键搞定的程序员来说,cradle是一个比较麻烦的事,有没有可以在命令行里面cradle的方法呢?
答案是肯定的。在msdn里面,微软提供了一个对Device Emulator Manager编程的方法(http://msdn.microsoft.com/en-us/library/bb887543.aspx)。大家可以从http://download.microsoft.com/download/3/6/1/361517d0-2054-4d41-af95-36d18e141df5/DEMAutomationSetup.msi下载这个例子,然后进行编译,编译一般会报错,说找不到DEMComInterface.tlb,这就需要更改一些工程的Include目录。例子的作者将Device Emulator装在d盘,我们只需要将这个目录改为自己的Device Emulator安装地方就可以了。DEMAutomation支持如下命令,其中就有cradle 。Device Emulator Manager提供的API可以参考http://msdn.microsoft.com/en-us/library/bb531169.aspx
List :列举模拟器
bringtofront [VMID|Name] :窗口置顶
connect [VMID|Name] :连接
cradle [VMID|Name]
clearsavestate [VMID|Name]
getconfiguration [VMID|Name] [existing device configuration file]
reset [VMID|Name]
uncradle [VMID|Name]
setconfiguration [VMID|Name] [device configuration file to create]
shutdown [VMID|Name]

参考网址:
http://msdn.microsoft.com/en-us/library/bb887543.aspx
http://msdn.microsoft.com/en-us/library/bb531169.aspx
http://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/84fb02dc-2510-46b4-98e9-541297d555c4