www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - HelloWordl in Webserver

reply "Xan" <xancorreu gmail.com> writes:
I dont' want to battle among languages, but I see that in Golang 
there is a beatiful solution to display HelloWorld program in web 
server [rosettacode.org/wiki/Hello_world/Web_server#Go]. I'm 
convinced there is a D equivalent?

Can someone say what's its aspect?

Thanks in advance,
Xan.
Mar 17 2012
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Saturday, 17 March 2012 at 20:08:24 UTC, Xan wrote:
 I'm convinced there is a D equivalent?

It all depends on the library. If you use my code https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff It looks like this: == import arsd.cgi; void hello(Cgi cgi) { cgi.write("Hello, world!"); } mixin GenericMain!hello; == You can build that as a cgi app to drop into any web server, a FastCGI app to use a longer running process on almost any webserver, or a HTTP server, standalone. Get cgi.d from my github then dmd hello.d cgi.d # builds cgi version dmd hello.d cgi.d -version=fastcgi # fastcgi, you also need the Fast CGI C library from the internet (search for libfcgi) or get netman.d and httpd.d and dmd hello.d cgi.d netman.d httpd.d -version=embedded_httpd # standalone, only works on linux
Mar 17 2012
next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 04/03/2012 10:45 AM, Xan wrote:
 On Tuesday, 3 April 2012 at 08:42:01 UTC, Xan wrote:
 I receive errors:

 xan gerret:~/proves/dlang-proves$ ls
 cgi.d functions.d httpd.d netman.d server.d
 xan gerret:~/proves/dlang-proves$ gdmd-4.6 server.d cgi.d netman.d
 httpd.d
 httpd.d:5: Error: module netman is in file 'arsd/netman.d' which
 cannot be read
 import path[0] = /usr/include/d2/4.6/i686-linux-gnu
 import path[1] = /usr/include/d2/4.6


 What fails?

 I use gdmd instead of dmd

It works when I change arsd.<name> to <name> in import.But I receive several warnings: $ gdmd-4.6 server.d cgi.d netman.d httpd.d Notice: As of Phobos 2.055, std.date and std.dateparse have been deprecated. They will be removed in February 2012. Please use std.datetime instead. netman.d:428: Error: function std.date.getUTCtime is deprecated I suspect your code is too elder. Thanks,

You can just comment out the code there (afaik it is only a custom formatting routine), or compile with the -d flag.
Apr 03 2012
prev sibling next sibling parent David <d dav1d.de> writes:
Am 19.03.2012 20:36, schrieb Xan:
 On Sunday, 18 March 2012 at 05:19:48 UTC, Kapps wrote:
 On Saturday, 17 March 2012 at 20:52:33 UTC, Xan wrote:
 So, there is not built-in functions?

 Thanks,
 Xan.

There's no built in webserver class, and it's not something that should be in the standard library in the first place.

A pain. A planning for that?

solution, just because it's not in Phobos? I don't understand why people hate to install (it's not even installing just downloading) libs.
Apr 03 2012
prev sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
 Not, I receive the error:

 $ gdmd-4.6 server.d cgi.d -version=embedded_httpd
 std.algorithm.indexOf has been scheduled for deprecation. You may want
 to use std.algorithm.countUntil instead.

Oh my, indexOf was deprecated? News to me.
 cgi.d:2231: Error: undefined identifier lastSocketError

-- Dmitry Olshansky
Apr 04 2012
prev sibling next sibling parent "Xan" <xancorreu gmail.com> writes:
So, there is not built-in functions?

Thanks,
Xan.

On Saturday, 17 March 2012 at 20:18:39 UTC, Adam D. Ruppe wrote:
 On Saturday, 17 March 2012 at 20:08:24 UTC, Xan wrote:
 I'm convinced there is a D equivalent?

It all depends on the library. If you use my code https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff It looks like this: == import arsd.cgi; void hello(Cgi cgi) { cgi.write("Hello, world!"); } mixin GenericMain!hello; == You can build that as a cgi app to drop into any web server, a FastCGI app to use a longer running process on almost any webserver, or a HTTP server, standalone. Get cgi.d from my github then dmd hello.d cgi.d # builds cgi version dmd hello.d cgi.d -version=fastcgi # fastcgi, you also need the Fast CGI C library from the internet (search for libfcgi) or get netman.d and httpd.d and dmd hello.d cgi.d netman.d httpd.d -version=embedded_httpd # standalone, only works on linux

Mar 17 2012
prev sibling next sibling parent "Kapps" <opantm2+spam gmail.com> writes:
On Saturday, 17 March 2012 at 20:52:33 UTC, Xan wrote:
 So, there is not built-in functions?

 Thanks,
 Xan.

There's no built in webserver class, and it's not something that should be in the standard library in the first place.
Mar 17 2012
prev sibling next sibling parent dennis luehring <dl.soluz gmx.net> writes:
Am 17.03.2012 21:08, schrieb Xan:
 I dont' want to battle among languages,

its maybe only a library battle
 but I see that in Golang
 there is a beatiful solution to display HelloWorld program in web
 server [rosettacode.org/wiki/Hello_world/Web_server#Go].

no its creates and simple webserver and displays your Hello world
 I'm
 convinced there is a D equivalent?

i think you've got only pure stocket library around std.socket or something like that - maybe you find an implementation of an web-server in the tango library
 Can someone say what's its aspect?

???
 Thanks in advance,
 Xan.

Mar 17 2012
prev sibling next sibling parent "Xan" <xancorreu gmail.com> writes:
On Sunday, 18 March 2012 at 05:19:48 UTC, Kapps wrote:
 On Saturday, 17 March 2012 at 20:52:33 UTC, Xan wrote:
 So, there is not built-in functions?

 Thanks,
 Xan.

There's no built in webserver class, and it's not something that should be in the standard library in the first place.

A pain. A planning for that?
Mar 19 2012
prev sibling next sibling parent simendsjo <simendsjo gmail.com> writes:
On Sun, 18 Mar 2012 06:19:47 +0100, Kapps <opantm2+spam gmail.com> wrote:

 On Saturday, 17 March 2012 at 20:52:33 UTC, Xan wrote:
 So, there is not built-in functions?

 Thanks,
 Xan.

There's no built in webserver class, and it's not something that should be in the standard library in the first place.

I think phobos should include a simple http server for testing purposes.
Mar 19 2012
prev sibling next sibling parent "Xan" <xancorreu gmail.com> writes:
I receive errors:

xan gerret:~/proves/dlang-proves$ ls
cgi.d  functions.d  httpd.d  netman.d  server.d
xan gerret:~/proves/dlang-proves$ gdmd-4.6 server.d cgi.d 
netman.d httpd.d
httpd.d:5: Error: module netman is in file 'arsd/netman.d' which 
cannot be read
import path[0] = /usr/include/d2/4.6/i686-linux-gnu
import path[1] = /usr/include/d2/4.6


What fails?

I use gdmd instead of dmd

On Saturday, 17 March 2012 at 20:18:39 UTC, Adam D. Ruppe wrote:
 On Saturday, 17 March 2012 at 20:08:24 UTC, Xan wrote:
 I'm convinced there is a D equivalent?

It all depends on the library. If you use my code https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff It looks like this: == import arsd.cgi; void hello(Cgi cgi) { cgi.write("Hello, world!"); } mixin GenericMain!hello; == You can build that as a cgi app to drop into any web server, a FastCGI app to use a longer running process on almost any webserver, or a HTTP server, standalone. Get cgi.d from my github then dmd hello.d cgi.d # builds cgi version dmd hello.d cgi.d -version=fastcgi # fastcgi, you also need the Fast CGI C library from the internet (search for libfcgi) or get netman.d and httpd.d and dmd hello.d cgi.d netman.d httpd.d -version=embedded_httpd # standalone, only works on linux

Apr 03 2012
prev sibling next sibling parent "Xan" <xancorreu gmail.com> writes:
On Tuesday, 3 April 2012 at 08:42:01 UTC, Xan wrote:
 I receive errors:

 xan gerret:~/proves/dlang-proves$ ls
 cgi.d  functions.d  httpd.d  netman.d  server.d
 xan gerret:~/proves/dlang-proves$ gdmd-4.6 server.d cgi.d 
 netman.d httpd.d
 httpd.d:5: Error: module netman is in file 'arsd/netman.d' 
 which cannot be read
 import path[0] = /usr/include/d2/4.6/i686-linux-gnu
 import path[1] = /usr/include/d2/4.6


 What fails?

 I use gdmd instead of dmd

It works when I change arsd.<name> to <name> in import.But I receive several warnings: $ gdmd-4.6 server.d cgi.d netman.d httpd.d Notice: As of Phobos 2.055, std.date and std.dateparse have been deprecated. They will be removed in February 2012. Please use std.datetime instead. netman.d:428: Error: function std.date.getUTCtime is deprecated I suspect your code is too elder. Thanks,
Apr 03 2012
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 3 April 2012 at 08:42:01 UTC, Xan wrote:
 I receive errors:

I changed some stuff since the beginning of thi thread. cgi.d now includes a http server without needing the other modules. So if you just get the new cgi.d, you can: dmd server.d cgi.d -version=embedded_httpd without bothering with the httpd.d nor netman.d
Apr 03 2012
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 3 April 2012 at 11:39:24 UTC, Timon Gehr wrote:
 You can just comment out the code there (afaik it is only a 
 custom formatting routine), or compile with the -d flag.

You're probably thinking of the std.date use in web.d. This one though is just older stuff that you don't need with the new cgi.d. BTW the Phobos team deciding to break std.date is still probably the #1 thing that has made me mad in D's life, though if -property becomes the default, we'll have a new king.
Apr 03 2012
prev sibling next sibling parent "Xan" <xancorreu gmail.com> writes:
 Thanks,

You can just comment out the code there (afaik it is only a custom formatting routine), or compile with the -d flag.

$ gdmd-4.6 -d server.d cgi.d netman.d httpd.d Notice: As of Phobos 2.055, std.date and std.dateparse have been deprecated. They will be removed in February 2012. Please use std.datetime instead. httpd.d:72: Error: undefined identifier peerAddress httpd.d:72: Error: constructor cgi.Cgi.this (long maxContentLength = cast(long)5000000, in const(immutable(char)[][string]) env = null, const(ubyte)[] delegate() readdata = null, void delegate(const(ubyte)[]) _rawDataOutput = null) is not callable using argument types (string[],immutable(ubyte)[],_error_,void delegate(const(ubyte)[])) What happens now?
Apr 03 2012
prev sibling next sibling parent "Xan" <xancorreu gmail.com> writes:
And with comment the UTC line I get:

s$ gdmd-4.6 server.d cgi.d netman.d httpd.d
Notice: As of Phobos 2.055, std.date and std.dateparse have been 
deprecated. They will be removed in February 2012. Please use 
std.datetime instead.
httpd.d:72: Error: undefined identifier peerAddress
httpd.d:72: Error: constructor cgi.Cgi.this (long 
maxContentLength = cast(long)5000000, in 
const(immutable(char)[][string]) env = null, const(ubyte)[] 
delegate() readdata = null, void delegate(const(ubyte)[]) 
_rawDataOutput = null) is not callable using argument types 
(string[],immutable(ubyte)[],_error_,void 
delegate(const(ubyte)[]))
Apr 03 2012
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 3 April 2012 at 19:07:10 UTC, Xan wrote:
 What happens now?

Use the newer standalone code: http://forum.dlang.org/thread/cifekffsnaimfsvuxlrw forum.dlang.org?page=2#post-pfojnbnvhuahnyviekut:40forum.dlang.org don't need netman.d anymore. Just use: gdmd server.d cgi.d -version=embedded_httpd to compile it.
Apr 03 2012
prev sibling next sibling parent "Xan" <xancorreu gmail.com> writes:
On Tuesday, 3 April 2012 at 13:33:19 UTC, Adam D. Ruppe wrote:
 On Tuesday, 3 April 2012 at 08:42:01 UTC, Xan wrote:
 I receive errors:

I changed some stuff since the beginning of thi thread. cgi.d now includes a http server without needing the other modules. So if you just get the new cgi.d, you can: dmd server.d cgi.d -version=embedded_httpd without bothering with the httpd.d nor netman.d

Not, I receive the error: $ gdmd-4.6 server.d cgi.d -version=embedded_httpd std.algorithm.indexOf has been scheduled for deprecation. You may want to use std.algorithm.countUntil instead. cgi.d:2231: Error: undefined identifier lastSocketError
Apr 04 2012
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 4 April 2012 at 08:04:14 UTC, Xan wrote:
 Not, I receive the error:

What version of D is that? lastSocketError is in phobos: http://dlang.org/phobos/std_socket.html#lastSocketError and it should work in windows and linux. Maybe your compiler is old.
Apr 04 2012