2011年5月30日 星期一

[Tips] Message Boundary

最近看文件看到message boundary這個名詞,突然愣了一下,經過東翻西找後,發現Richard Stevens大師寫的真清楚,以下節錄自UNIX Network Programming, Volume 2, Second Edition: Interprocess Communications

4.10 Streams and Message (p.67)
No record boundaries exist - reads and writes do not examine the data at all. The data is a byte stream with no interpretation done by the system. If any interpretation is desired, the writing process and the reading process must agree to it a priori and do it themselves.
1.Special termination sequence in-band: many Unix applications use the newline character to delineate each message.
2.Explicit length: each record is preceded by its length. One advantage to this technique is that escaping a delimiter that appears in the data is unnecessary, because the receiver does not need to scan all the data,looking for the end of each record.
3.One record per connection: the application closes the connection to its peer to indicate the end of a record. The requires a new connection for every record, but is used with HTTP 1.0.

只會用不會說果然不是真懂阿...

2011年5月24日 星期二

[Qt] Qt學習網路資源

最近在搞Qt,官方網站提供了不少的資源,不但有pdf的講義,還有video的教學,另外Qt Developer Days的內容也值得參考

如果要看中文的內容,當然首推良葛格學習筆記,自由軟體技術支援庫也有不錯的介紹

未來有看到好的網站,也會持續更新

/** update @ 2011-10-13 **/
零基础学Qt4编程作者blog

/** update @ 2011-10-12 **/
對岸有個不錯的教學網,yafeilinux.com----開源 共享 自由

/** update @ 2011-05-31 **/
目前我看到資源最豐富的Qt技術部落格CuteQt Blog

2011年5月23日 星期一

[Network] Three-Way Handshake in TCP

TCP的three-way handshake是在哪一個階段發生的?

environment:
* foo: 192.168.104.1, 執行server.c
* bar: 192.168.104.100, 執行client.c

foo$ vim server.c
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main()
{
    int serverfd, clientfd;
    struct sockaddr_in server;
    struct sockaddr_in client;
    socklen_t len;
    server.sin_family = AF_INET;
    server.sin_port = htons(8080);
    server.sin_addr.s_addr = inet_addr("192.168.104.1");
    serverfd = socket(AF_INET, SOCK_STREAM, 0); 
    bind(serverfd, (struct sockaddr*)&server, sizeof(server));
    listen(serverfd, 10);
    len = sizeof(client);
    clientfd = accept(serverfd, (struct sockaddr*)&client, &len);
    close(clientfd);
    close(serverfd);
    return 0;
}
foo$ gcc -Wall -g server.c -o server

bar$ vim client.c
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main()
{
    int serverfd;
    struct sockaddr_in server;
    serverfd = socket(AF_INET, SOCK_STREAM, 0); 
    server.sin_family = AF_INET;
    server.sin_port = htons(8080);
    server.sin_addr.s_addr = inet_addr("192.168.104.1");
    connect(serverfd, (struct sockaddr*)&server, sizeof(server));
    close(serverfd);

    return 0;
}
bar$ gcc -Wall -g client.c -o client

單步執行server.c, 在accept()被block住
foo$ cgdb ./server

這時還沒有送出任何的封包

單步執行client.c到connect()
bar$ cgdb ./client

bar在connect()時進行three-way handshake,與foo傳送SYN,SYN/ACK,ACK封包

bar關閉socket,送出FIN封包(若由client關閉socket,則由foo送出FIN封包)

2011年5月10日 星期二

[Tips] Rebuild media file from wireshark logs

How to rebuild media file when doing RTSP packet captured by Wireshark?

1.in any RTP packet(sometimes 'video-stream' is shown), right click on the package->'Decode As' and choose 'RTP' in Transport tab
2.choose from context menu 'Analyze'->'follow UDP stream'
3.save as wherever you like...

references:
* Rebuild media file from wireshark logs

2011年5月7日 星期六

[Tips] 線上資源

紀錄一下目前常在用的線上資源,常保更新

* YouTube影片下載:
KeepVid

* Youtube/Vimeo/優酷/土豆網/Google Videos等影片下載
TubGet

* HTML編碼/解碼:
HTML Encoder

* 線上JavaScript排版:
Online javascript beautifier

* 線上程式排版(PHP/Java/C++/C/Perl/JavaScript/CSS):
Pretty Printer

2011年5月1日 星期日

[多媒體] VLC Multicast Streaming

最近在弄一些網路串流的東西,有時候會拿VLC先做測試
想用VLC收multicast的streaming,只要下
vlc udp://@server.ip:port

如果連不上,大概需要注意幾件事是否正確
1.IGMP的版本,通常需支援v2以上的版本才行
2.Reverse Path Filtering需要關閉
3.Routing需要設對

總而言之,寫了簡單的shell script幫助快速設定
#!/bin/bash
# force IMGP v2
echo 2 > /proc/sys/net/ipv4/conf/eth0/force_igmp_version

# set no reverse path lookup
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter

# set multicast route
route add -net 224.0.0.0 netmask 224.0.0.0 dev eth0

reference:
* UDP multicast playing and VLC
* [SOLVED] Multicast & mythtv tuning issues with kernel>2.6.30