-
Notifications
You must be signed in to change notification settings - Fork 12
Description
'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.
- 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'?
- 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(kozjakm1@gmail.com):
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指令,而非一接獲資料就傳送.