What will happen if one can access bbs in matlab?
Well, actually, nothing really.
But it can be an interesting experience, and in my philosophy it counts to create some interesting things for this boring world.
And all these lead to a crazy plan: Materm, a bbs client in matlab.
Here is its first piece of code. With the comments, I think everything is self-explained-----after all it's so short.
The only thing worth while mentioning here is the problems I have fixed today:
a. Howto read non-url data from internet-----for url, we can use urlread directly.
b. How does matlab represent Chinese characters and how to convert them into GB presentation.-----Matlab uses unicode internally and provides "unicode2native" for conversion.
c. In a bbs system, on enter is represented by 2 characters and their ascii are "10" and "13" resp.
The code and its output is given below
>> t = tcpip('bbs.newsmth.org',23,'InputBufferSize',2048);% 开一个端口
fopen(t)
A=fread(t);%读入,貌似这样读会把所有buf里面收到的东西都读进来----不过我一直不知道他是怎么判断停止的....
B=char(A)';%这个地方要转置一下,否则后面的函数不认
B=regexprep(B,'\x1B\[m','\x1B\[0m');%先把*[m变成*[0m,免得麻烦
B=regexprep(B,'\x1B\[\d+(;\d+)*m','');% 目前简化处理,所有的ascciart全部忽略
C=native2unicode(uint8(B));
C=regexprep(C,'\xD\xA','\n')%合并回车
fclose(t)
Warning: The specified amount of data was not returned within the Timeout period.
C =
????????[H[J[1;1H[H[J
;, ;,
;; , ;; ,
,,,;,;;, ,;' ''';';;;'''''
;;;;';' ┌──┐┌┐┌┐┌──┐┌┐┌┐ ;;;;';
;; ;; '; │ ─┤│└┘│└┐┌┘│└┘│ ;; ;; ';,
,; ;; ';, ├— │││││ ││ │┌┐│ ;; ;; ';;,
;' ;; ';;, └──┘└┴┴┘ └┘ └┘└┘ ,'' ;; ';'
' '';' ' ;;
__ ____ ~╲
/ \ _╱ ╲ \
╲ /_╱ │ /
金 鼠 献 瑞 __/, /-╯ 鼠 年 大 吉
"╲ ╱
﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉ ﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉
网 bbs.newsmth.net 电 bbs4.newsmth.net
通 www.newsmth.net 信 www4.newsmth.net
北京市通信管理局ICP备案号 (京ICP证050249号)
[22;1H欢迎光临 ◆水木社区◆ 上线人数 11360[最高: 23357](4879 WWW GUEST)
试用请输入 `guest', 注册请输入`new', add `.' after your ID for BIG5
请输入代号:
>>
2008年5月10日星期六
Materm, a crazy plan
订阅:
博文评论 (Atom)
0 comments:
发表评论