View mode: basic / threaded / horizontal-split · Log in · Help
November 26, 2012
telnet and D
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...
November 27, 2012
Re: telnet and D
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..
November 27, 2012
Re: telnet and D
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
November 27, 2012
Re: telnet and D
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.
November 27, 2012
Re: telnet and D
> 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 :)
November 28, 2012
Re: telnet and D
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();
}
November 29, 2012
Re: telnet and D
> 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 :)
Top | Discussion index | About this forum | D home