Giter VIP home page Giter VIP logo

ptt-bot's People

Contributors

andy23512 avatar chenchenbox avatar darbychang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ptt-bot's Issues

New node package: 'node-telnet-client'

'node-telnet-client'(https://github.com/mkozjak/node-telnet-client) 實作了telnet client端,應該是根據RFC 854 spec(http://tools.ietf.org/html/rfc854) , 根據作者的回信,利用偵測telnet sever回傳的data偵測prompt, 來判斷是否已經收集完資料.

信件紀錄:
Ask from chenchen:

Hi,

I just found your contribution about telnet connection in client from npm.

I am current working on a project which involves create a socket(connection) to a BBS sever. I have some problem want to discuss with you. Since I am not familiar to tcp connection, my problem may sounds stupid. Please forgive me if these are really fundamental.

Here are my problem.

  1. I've tried to use native node package called "net" to realize the socket between my computer(client) to BBS sever before, and it quite doing good. And l've seen the intro about your package. They are quite similar. What is the main difference between your contribution 'telnet-client' and native package 'net'?
  2. I've meeting trouble recently about handling received data from bbs sever. How can I detect the bbs sever has just finished senting data? In details, when my client has sent an command to bbs sever, sever will respond a bulls of data. And I used to use 'data' event from connection listener, it will be trigger while a chunk of data has been received. My purpose is to reconstruct the whole screen of terminal, and I found I usually only got part of screen of terminal when 'data' event is triggered. Is there any way I can detect if this is the end of screen(in other words, the data was received completely). Is this in related to the Buffer concept in readable stream?

I am looking forward your respond. Hope everything is good with you.

Reply from mkozjak([email protected]):

Hi!

telnet-client uses 'net' as its basis. telnet-client is a telnet implementation, thus, it provides you with simple functions to get responses from telnet sessions. Without it, you'd need to take care of telnet on your own, and that's, like, 200 lines of additional code. That's the basic difference.

How I am looking for finished response is waiting for the prompt. Once I receive it, I declare an end of response.
https://github.com/mkozjak/node-telnet-client/blob/master/lib/telnet-client.js (line 154)

Have you tried using net's socket.setTimeout()? If you open a connection each time you want to get some data, then the timeout is pretty much an indication you're not receiving anything. Just set a timeout each time the socket is opened.

Hope some of this helps!

With regards,
Mario Kozjak

補:
Event: 'timeout' (http://nodejs.org/api/net.html#net_event_timeout):

Emitted if the socket times out from inactivity. This is only to notify that the socket has been idle. The user must manually close the connection.

See also: socket.setTimeout()

補:
經過測試, timeout參數設定為500ms較為OK., 應當更改程式, 當timeout觸發時才執行傳送下一個ptt指令,而非一接獲資料就傳送.

Create New version for async style.

master目前的架構為先新增所有開發者下的指令到指令集, 在後端再慢慢消化指令.
缺點為目前的方式可能無法有以下寫法:

myBot.toArticle('30009',function(){
    console.log("執行toArticle的callback");
});
if(comment > 50){
    myBot.fetchArticle(function(){
       console.log(myBot.getArticle());
       console.log("執行fetchArticle的callback");
    });
}
else{
       //do nothing
}
myBot.toArticle('30010',function(){
    console.log("執行toArticle的callback");
});

即在開法者的指令上無法有分支.

考慮新增一隻branch, 利用async套件(https://github.com/caolan/async) 嘗試看看新架構.
大致想法為,
第二個指令放入第一個指令的callback,
第三個指令放入第二個指令的callback,
第四個指令放入第三個指令的callback....一直接下去

開發者端的程式寫起來會較醜, 但可用async套件美化.

Add New branch parse-data-ver

parse-data-version保存最初解決漏字問題的解法(模擬整個終端機), 將予以保留和master各自發展, master將發展為直接向ptt-sever要求重整過的畫面, 較為簡單, 出錯率較為不高.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.