2013年1月17日 星期四

Study network transmission format



Introduction

POST
it's a simple solution for transmission data to server, and server can capture the value by pair-element(like php, $_POST['company'])
  • Example from J2ME
    try {
        HttpConnection c = (HttpConnection)Connector.open(URL);
        c.setRequestMethod(HttpConnection.POST);
        c.setRequestProperty("Content-Type","application/x-www-form-urlencoded");//MUST
        String msg = "uuid=444566&imei=9ddd999&jblend_license=2223";
        byte[] data = msg.getBytes();
        for(int x=0;x<data.length;x++)
            System.out.print(data[x]+",");
     
        c.setRequestProperty("Content-length",""+msg.getBytes().length);//MUST
        OutputStream os = c.openOutputStream();
        os.write(data);
        os.flush();
        int rc = c.getResponseCode();
        System.out.println(""+rc);
     
    } catch (IOException e) {
        System.out.println("IOException:"+e.getMessage());
    }
XML (eXtensible Markup Language)
XML design for describing data.
it's Rich Documents : easy to describe the complex structure
it's Metadata
it's Configuration Files : using to set software parameter
  • Example
    <?xml version="1.0"?>
    <note>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
    </note>
  • who use XML
    ANT, Android's layout ... etc
JSON(JavaScript Object Notation)
it's a light-weight language for exchange data. the JavaScript can easy read it by eval(). but it's not only for JavaScript
  • Example
{"2": {"nick_name": "kan", "full_name": "Kan Kan"}, "4": {"nick_name": "mitsuhiko", ...}, ...}
  • who use JSON
    plurk, facebook, twitter
YAML(YAML Ain't Markup Language)
  • Example
    Name: Gary
    Profile:
        Birth: 1975-04-43
        Addr:
            - City: Taipei
              Road: Chung-Shoang
              Number: 20
              Flood: 3
            - City: TaoYuan
              Road: LongChung
              Number: 10
              Flood: 2
        Blood Type: A
    Score: 0.98
  • Who use YAML
    Google app engine(configure file)
Suggestion Architecture
Server -> Client : JSON or XML
Client -> Server : POST
For example, the PLURK API for search function:
/API/PlurkSearch/search
  • Returns the latest 20 plurks on a search term.
  • Required parameters:
    • api_key: Your Plurk API key.
    • query: The query after Plurks.
  • Optional parameters:
    • offset: A plurk_id of the oldest Plurk in the last search result.
  • Successful return:
    A JSON list of plurks that the user have permissions to see:
    [{"id": 3, "content": "Test", "qualifier_translated": "says", "qualifier": "says", ...}, ...]
Result
table. the result of comparing each format

POST
XML
JSON
YAML
readability
low
high
median
high
performance
high
low
median
median-high
security
low
high
median
median
security : parser for checking well-form

Conclusion

the purpose of stage activation get report on server(grails)
it's not complication structure(tree or nest)
it's not need to high readability
it's not need to easy to integrate each platform(like different web-platform, mobile...)
it's only good at security

2012年7月30日 星期一

A New Way to Share/Connected each other : Heyzap


   玩社群遊戲最怕沒有朋友,以及不知道有什麼最新的好玩,Heyzap創造另一種專屬於遊戲的社群平台,透過check in的方式來告知玩家哪款新遊戲好玩與否;其實我媽就是屬於這類型的玩家,聽說開心水族箱為了彼此互助,甚至創辦社團作為溝通的管道(而且還不少人做這類似的事情),趕快出中文版滿足我媽吧!

Reference :



2012年6月12日 星期二

[Android] AsyncTask vs Handler vs Thread

起源:


Android裡面如何使用multi-thread,如果照需求去搜尋文件將得到三種物件:
  1. AsyncTask
  2. Handler
  3. Thread 
這 AsyncTask 和Thread共同的地方就是會開啟另一個Thread運作

而AsyncTask和Handler簡化了Thread與UIThread互動,這表示單純用Thread會需要自己實作Runnable然後塞進去Activity.runOnUiThread(Runnable)

而AsyncTask和Handler的差別在於AsyncTask只要實作好callback interface就可以與UI元件互動,而Handler要自己sendMessage/handleMessage

參考資料: