www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - telnet and D

reply maarten van damme <maartenvd1994 gmail.com> writes:
I was wondering if there ever was a telnet library written for D? I've
been unable to find anything. I also tried using curl but the timeout
options seem to fail here. I've tried writing a minimalistic client
myself but the library will be used to connect to some routers and
either something is wrong in my option negotiation or that router
doesn't support the full telnet protocol.

I can't use socketstreams because it strangely counts "255" as a
newline and I'm afraid it'll mess things up when I try to send
different data and socketstream is going to be deprecated...
Nov 26 2012
next sibling parent reply 1100110 <0b1100110 gmail.com> writes:
On 11/26/2012 04:58 PM, maarten van damme wrote:
 I was wondering if there ever was a telnet library written for D? I've
 been unable to find anything. I also tried using curl but the timeout
 options seem to fail here. I've tried writing a minimalistic client
 myself but the library will be used to connect to some routers and
 either something is wrong in my option negotiation or that router
 doesn't support the full telnet protocol.

 I can't use socketstreams because it strangely counts "255" as a
 newline and I'm afraid it'll mess things up when I try to send
 different data and socketstream is going to be deprecated...
Have you taken a look at vibe.d? http://vibed.org IIRC, telnet is simple, so it shouldn't be too difficult..
Nov 26 2012
next sibling parent reply maarten van damme <maartenvd1994 gmail.com> writes:
Haven't looked at vibe.d yet because it looked more like a library for
writing web apps and  normal sockets should be enough.


Didn't know about Tango, I'll try deciphering the original d1 module.
Nov 27 2012
parent reply 1100110 <0b1100110 gmail.com> writes:
On 11/27/2012 01:56 PM, maarten van damme wrote:
 Haven't looked at vibe.d yet because it looked more like a library for
 writing web apps and  normal sockets should be enough.


 Didn't know about Tango, I'll try deciphering the original d1 module.
... I mean no offense, but that sounds painful. vibe.d is very modular, just import what you need. I hate to push it, but it has very good documentation and examples. Its designed for web apps, but it makes a nice little web library as well. import vibe.vibe; void main() { auto client = new HttpClient; client.connect("www.google.com", 80); auto res = client.request((req){ req.url = "/"; }); logInfo("Response: %d", res.statusCode); foreach( k, v; res.headers ) logInfo("Header: %s: %s", k, v); (new NullOutputStream).write(res.bodyReader); client.disconnect(); }
Nov 28 2012
parent maarten van damme <maartenvd1994 gmail.com> writes:
 vibe.d is very modular, just import what you need.
 I hate to push it, but it has very good documentation and examples.

 Its designed for web apps, but it makes a nice little web library as well.

 import vibe.vibe;

 void main()
 {
     auto client = new HttpClient;
     client.connect("www.google.com", 80);

     auto res = client.request((req){
         req.url = "/";
     });

     logInfo("Response: %d", res.statusCode);

     foreach( k, v; res.headers )
         logInfo("Header: %s: %s", k, v);

     (new NullOutputStream).write(res.bodyReader);
     client.disconnect();
 }
That does indeed look clean. Now I'm using a ubyte[1] buffer to try and read single bytes from my sockets. their tcp example looks pretty clean: import vibe.d; static this() { auto conn = connectTcp("time-b.timefreq.bldrdoc.gov", 13); logInfo("The time is: %s", cast(string)conn.readAll()); } let's see how it'll hold up when I try to deal with raw bytes :)
Nov 29 2012
prev sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
 IIRC, telnet is simple, so it shouldn't be too difficult..
Turns out it indeed was simple. My option negotiation had a bug :D my (primitive) telnet client works now :)
Nov 27 2012
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-11-26 23:58, maarten van damme wrote:
 I was wondering if there ever was a telnet library written for D? I've
 been unable to find anything. I also tried using curl but the timeout
 options seem to fail here. I've tried writing a minimalistic client
 myself but the library will be used to connect to some routers and
 either something is wrong in my option negotiation or that router
 doesn't support the full telnet protocol.

 I can't use socketstreams because it strangely counts "255" as a
 newline and I'm afraid it'll mess things up when I try to send
 different data and socketstream is going to be deprecated...
Don't know how useful it is but Tango contains an Telnet (tango.net.ftp.Telnet) module as a part of its FTP module. It used to contain more code, you can look back at the changeset history. https://github.com/SiegeLord/Tango-D2 http://www.dsource.org/projects/tango/docs/current/ -- /Jacob Carlborg
Nov 26 2012