www.digitalmars.com         C & C++   DMDScript  

D - Help needed with socket.d

reply "Christian Lesage" <christian.lesage.1 agora.ulaval.ca> writes:
Hi folks!

D seems to have most important features I want in a language: garbage
collection, strings, dynamic arrays and associative arrays. I've used
scripting
languages until now because they had these features, but I always wished
there was a compiled language which would offer them. Then, I think D
deserves a try.

Easy TCP/IP is another feature I need. Pavel Minayev created the D sockets
library, "a set of classes encapsulating Windows Sockets 2 functionality".
Great. Mike Wynn posted his fixes to this library on January 23, 2003. This
is the file I am reposting here.

Now, here's my problem. Even using Mike's "socket.d", I can't compile
Pavel's example "httpget.d". The compiler yields:

C:\Program Files\DIDE\Projects\httpget\httpget.d(21): cannot create instance
of abstract class TCPSocket

Also, I think that I have to link the whole thing with "ws2_32.lib", but how
can I get this done?

I guess my questions will seem trivial to some of you. However, I would
really appreciate some help. BTW, I'm using DIDE.

Christian Lesage



begin 666 socket.d

M4&%V96P (D5V:6Q/;F4B($UI;F%Y978-"B J($-O<'ER:6=H=" H8RD ,C P
M,R!-:6ME(%=Y;FX /&UI:V4N=WEN;D!L.&YI9VAT+F-O+G5K/ T*("H-"B J
M(%!E<FUI<W-I;VX =&\ =7-E+"!C;W!Y+"!M;V1I9GDL(&1I<W1R:6)U=&4 
M86YD('-E;&P =&AI<R!S;V9T=V%R90T*("H 86YD(&ET<R!D;V-U;65N=&%T
M:6]N(&9O<B!A;GD <'5R<&]S92!I<R!H97)E8GD 9W)A;G1E9"!W:71H;W5T
M(&9E92P-"B J('!R;W9I9&5D('1H870 =&AE(&%B;W9E(&-O<'ER:6=H="!N

M=&AA="!C;W!Y<FEG:'0 ;F]T:6-E(&%N9"!T:&ES('!E<FUI<W-I;VX ;F]T
M:6-E(&%P<&5A< T*("H :6X <W5P<&]R=&EN9R!D;V-U;65N=&%T:6]N+B  
M075T:&]R(&UA:V5S(&YO(')E<')E<V5N=&%T:6]N<R!A8F]U= T*("H =&AE
M('-U:71A8FEL:71Y(&]F('1H:7, <V]F='=A<F4 9F]R(&%N>2!P=7)P;W-E
M+B!)="!I<R!P<F]V:61E9 T*("H (F%S(&ES(B!W:71H;W5T(&5X<')E<W, 
M;W( :6UP;&EE9"!W87)R86YT>2X-"B J+PT*;6]D=6QE('-O8VME=#L-"FEM

M7V)E9VEN=&AR96%D*'9O:60 *"HI*'9O:60J*2P =6EN="P =F]I9"HI.PT*



M:&%R6UT ;7-G*0T*"7L-" D)<W1A=&EC(&-H87);,C!=(&YU;3L-" D)97)R
M;F\ /2!74T%'971,87-T17)R;W(H*3L-" D)<W5P97(H;7-G('X ;G5M6S  


M8VQA<W, 0V]N;F5C=$5R<F]R.B!3;V-K971%<G)O< T*>PT*"71H:7,H8VAA


M+R!I;B!F;W)M(&]F(&)Y=&4 <W1R96%M("A7:6Y3;V-K,B!33T-+7U-44D5!
M32D-"F-L87-S(%-T<F5A;5-O8VME=#H
M(%-/0TM%5"!S;V-K970 /2!C87-T*%-/0TM%5"DP.PT*"0T*"2\O(&)I;F1S
M(&]B:F5C="!T;R!A;B!E>&ES=&EN9R!S;V-K970[('5S92!W:71H(&-A<F4A

M970 /2!S.PT*"0ER96%D86)L92 ]('=R:71E86)L92 ](&-O;FYE8W1E9#L-

M;V-K970 :7, 8V]N;F5C=&5D+"!F86QS92!O=&AE<G=I<V4-" EB:70 8V]N


M=6QT(#T

M<V]C:V5T*'-O8VME="P 1DE/3D))3RP )FYB*3L-" D):68 *')E<W5L=" ]




M970L(%-$7T)/5$ I.PT*"0D)8VQO<V5S;V-K970H<V]C:V5T*3L-" D)"7)E
M861A8FQE(#T =W)I=&5A8FQE(#T

M97)E(&ES(')E8V5I=F5D(&1A=&$ :6X =&AE(&)U9F9E<BP-" DO+R!S;R!C
M86QL('1O(')E860H*2!W;W5D;&XG="!B;&]C:RP 9F%L<V4 ;W1H97)W:7-E



M;B!S96QE8W0H,"P )F9D+"!N=6QL+"!N=6QL+" F='8I(#X ,#L-




M8V%S="AC:&%R*BD 8G5F9F5R+"!S:7IE+" P*3L-" D):68 *"%R97-U;'0I


M8V%S92!74T%%3D]40T].3CH-" D)"6-A<V4 5U-!14-/3DY215-%5#H-" D)

M3TY.04)/4E1%1#H-" D)"6-A<V4 5U-!14Y%5%)%4T54. T*"0D)"61I<V-O



M:60J(&)U9F9E<BP =6EN="!S:7IE*0T*"2\O('-I;F-E(&EN+6)L;V-K<R!A



M.PT*"0EI9B H<F5S=6QT(#T](%-/0TM%5%]%4E)/4BD-" D)"71H<F]W(&YE
M=R!7<FET945R<F]R*")S;V-K970 9F%I;&5D('1O('-E;F0 9&%T82(I.PT*







M(#T

M861D<BYB6S%=(#T 8C([(&EP861D<BYB6S)=(#T 8C,[(&EP861D<BYB6S-=
M(#T


M(&AO<W0 /2!G971H;W-T8GEN86UE*'1O4W1R:6YG>BAH;W-T;F%M92DI.PT*
M"0EI9B H:&]S="D-" D)"6EP861D<BYA9&1R97-S(#T *BAC87-T*'5?;&]N




M(BP :7!A9&1R+F);,%TL(&EP861D<BYB6S%=+"!I<&%D9'(N8ELR72P :7!A




M:&ES+FEP(#T
M:7,H=6)Y=&4 8C$L('5B>71E(&(R+"!U8GET92!B,RP =6)Y=&4 8C0L('5S
M:&]R="!P;W)T*0T*"7L-" D)=&AI<RAN97< 25 H8C$L(&(R+"!B,RP 8C0I

M="!P;W)T*0T*"7L-" D)=&AI<RAN97< 25 H:&]S=&YA;64I+"!P;W)T*3L-




M"71H:7,H*2![('T-" T*"2\O(&-O;FYE8W1S('1O(&=I=F5N($EN=&5R;F5T

M;FYE8W0H:6$I.PT*"7T-" T*"2\O(&-O;FYE8W1S('1O(&=I=F5N($EN=&5R
M;F5T(&%D9')E<W,-" ET:&ES*'5B>71E(&(Q+"!U8GET92!B,BP =6)Y=&4 

M(&(R+"!B,RP 8C0L('!O<G0I.PT*"7T-" D-" DO+R!C;VYN96-T<R!T;R!G
M:79E;B!H;W-T;F%M90T*"71H:7,H8VAA<EM=(&AO<W1N86UE+"!U<VAO<G0 

M" DO+R!C;VYN96-T<R!T;R!G:79E;B!);G1E<FYE="!A9&1R97-S+"!T:')O


M"7-O8VME=" ]('=I;G-O8VLN<V]C:V5T*%!&7TE.150L(%-/0TM?4U1214%-

M86UI;'D /2!01E])3D54.PT*"0ES82YS:6Y?861D<BYS7V%D9'( /2!I82YI
M<"YI<&%D9'(N861D<F5S<SL-" D)<V$N<VEN7W!O<G0 /2!H=&]N<RAI82YP
M;W)T*3L-" D):68 *'=I;G-O8VLN8V]N;F5C="AS;V-K970L(&-A<W0H<V]C
M:V%D9'(J*2 F<V$L('-A+G-I>F4I*0T*"0D)=&AR;W< ;F5W($-O;FYE8W1%
M<G)O<B B8V%N;F]T(&-O;FYE8W0B*3L-" D)<F5A9&%B;&4 /2!W<FET96%B
M;&4 /2!T<G5E.PT*"7T-" T*"2\O(&-O;FYE8W1S('1O(&=I=F5N($EN=&5R
M;F5T(&%D9')E<W,-" EV;VED(&-O;FYE8W0H=6)Y=&4 8C$L('5B>71E(&(R
M+"!U8GET92!B,RP =6)Y=&4 8C0L('5S:&]R="!P;W)T*0T*"7L-" D)8V]N
M;F5C="AN97< 26YT97)N971!9&1R97-S*&(Q+"!B,BP 8C,L(&(T+"!P;W)T

M;VED(&-O;FYE8W0H8VAA<EM=(&AO<W1N86UE+"!U<VAO<G0 <&]R="D-" E[

M="DI.PT*"7T-"GT-" T*+R\ <W1R96%M+6)A<V5D('-E<G9E<B!S;V-K970-
M"F-L87-S(%-E<G9E<E-O8VME= T*>PT*"7!R;W1E8W1E9"!33T-+150 <V]C
M:V5T(#T 8V%S="A33T-+150I,#L-" EP<F]T96-T960 8FET(&U?;&ES=&5N
M:6YG(#T
M;F-O;6EN9R!C;VYN96-T:6]N<PT*"79O:60 ;&ES=&5N*"D >R!L:7-T96XH




M92!I9B!S;V-K970 :7, ;&ES=&5N:6YG+"!F86QS92!O=&AE<G=I<V4-" EB
M:70 ;&ES=&5N:6YG*"D >R!R971U<FX ;5]L:7-T96YI;F<[('T-" T*"2\O
M('-H=71S(&1O=VX =&AE('-E<G9E< T*"79O:60 <VAU=&1O=VXH*0T*"7L-
M" D):68 *'-O8VME="D-" D)>PT*"0D)=VEN<V]C:RYS:'5T9&]W;BAS;V-K
M970L(%-$7T)/5$ I.PT*"0D)8VQO<V5S;V-K970H<V]C:V5T*3L-" D)"6U?
M;&ES=&5N:6YG(#T






M<R!40U!397)V97(Z(%-E<G9E<E-O8VME= T*>PT*"7!R:79A=&4 8FET(&U?

M:7,H=7-H;W)T(' I('L <&]R="AP*3L ?0T*"0T*"2\O(&-R96%T97, =&AE


M970 /2!W:6YS;V-K+G-O8VME="A01E])3D54+"!33T-+7U-44D5!32P 25!0

M(#T 4$9?24Y%5#L-" D)<V$N<VEN7V%D9'(N<U]A9&1R(#T ,#L-" D)<V$N
M<VEN7W!O<G0 /2!H=&]N<RAP*3L-" D)8FEN9"  <V]C:V5T+"!C87-T*'-O

M"2\O(&%C8V5P=', 86YY(&EN8V]M:6YG(&-O;FYE8W1I;VYS+"!F:6QL<R!T
M:&4 9VEV96X-" DO+R!);G1E<FYE=$%D9')E<W, =VET:"!C;&EE;G0 861D


M;B!C;W5L9&XG="!B92!A8V-E<'1E9 T*"5-T<F5A;5-O8VME="!A8V-E<'0H


M;V-K+F%C8V5P="  <V]C:V5T+"!C87-T*'-O8VMA9&1R*BD )G-A+" F<V%L
M96X *3L-" D):68 *')E<W5L=" ]/2!)3E9!3$E$7U-/0TM%5"D-" D)"71H

M;F< 8V]N;F5C=&EO;B(I.PT*"0EI82YI<"YI<&%D9'(N861D<F5S<R ]('-A
M+G-I;E]A9&1R+G-?861D<CL-" D):6$N<&]R=" ](&YT;VAS*'-A+G-I;E]P
M;W)T*3L-" D)4W1R96%M4V]C:V5T(', /2!N97< 4W1R96%M4V]C:V5T*')E

M=', 86YY(&EN8V]M:6YG(&-O;FYE8W1I;VYS+"!R971U<FYS(&-O<G)E<W!O

M971U<FX 86-C97!T*&YE=R!);G1E<FYE=$%D9')E<W,I.PT*"7T-" D-" EB
M:70 8VQI96YT5&AR96%D<R I('L <F5T=7)N(&U?8VQI96YT5&AR96%D<SL 
M?0T*"0T*"79O:60 8VQI96YT5&AR96%D<RAB:70 8BD >R!M7V-L:65N=%1H

M;F5C=&EO;G, :6X 82!L;V]P(&%N9"!T<F%N<V9E<G,-" DO+R!C;VYT<F]L
M('1O(&]N0V]N;F5C=&EO;B I.R!I9B!C;&EE;G14:')E861S(&ES('1R=64L
M('-T87)T<PT*"2\O(&$ <V5P87)A=&4 =&AR96%D(&9O<B!E86-H(&YE=R!C


M971!9&1R97-S.PT*"0D)4W1R96%M4V]C:V5T(', /2!A8V-E<'0H:6$I.PT*

M*0T*"0D)>PT*"0D)"6-O;FY?9&%T82!C;B ](&YE=R!C;VYN7V1A=&$H('1H


M*',L(&EA*3L-" D)?0T*"7T-" D-" DO+R!S=&%R=', <V5R=F5R3&]O<" I

M"7L-" D)7V)E9VEN=&AR96%D*"9B9U-E<G9E<E1H<F5A9"P ,"P =&AI<RD[


M:6]N('!A<W-E<R!C;VYT<F]L('1O('-I;7!L:69I960 =F5R<VEO;B!W:&EC





M(&=E;F5R:6, =F5R<VEO;B!I<R!O=F5R<FED96X-" EP<F]T96-T960 =F]I





M"0D)<V]C:V5T(#T <V]C:V5T,#L-" D)"6EA("  (" ](&EA,#L-" D)?0T*


M97)N*$,I('-T871I8R!V;VED(&-O;FYE8W1I;VY4:')E860H=F]I9"H 87)G
M*0T*"7L-" D)8V]N;E]D871A(&-N(#T 8V%S="AC;VYN7V1A=&$I(&%R9SL-
M" D)8VXN<V5R=F5R+F]N0V]N;F5C=&EO;BAC;BYS;V-K970L(&-N+FEA*3L-






M"7L-" D)<VAU=&1O=VXH<V]C:V5T+"!31%]"3U1(*3L-" D)8VQO<V5S;V-K

M:7, <F5C96EV960 9&%T82!I;B!T:&4 8G5F9F5R+"!S;PT*"2\O(&-A;&P 
M=&\ <F5A9"!F=6YC=&EO;G, =VEL;"!N;W0 8FQO8VLL(&9A;'-E(&]T:&5R
M=VES90T*"6)I="!D871A4F5C96EV960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"71H<F]W(&YE=R!7
M<FET945R<F]R*")S;V-K970 9F%I;&5D('1O('-E;F0 9&%T86=R86TB*3L-
M" D)<F5T=7)N(')E<W5L=#L-
M<F%M(&%N9"!S=&]R97, :6YF;W)M871I;VX 86)O=70 =&AE(&AO<W0-" DO
M+R!T:&%T('-E;G0 :70L(')E='5R;G, 86-T=6%L(&YU;6)E<B!O9B!B>71E

M97( =&AA;B!S:7IE(&]F('1H92!S=7!P;&EE9"!B=69F97(L( T*"2\O(&5V
M97)Y=&AI;F< =&AA="!D;V5S;B=T(&9I="!I;B!B=69F97( :7, 3$]35"P 
M86YD(')E='5R; T*"2\O('9A;'5E(&ES(&=R96%T97( =&AA;B!S:7IE(&]F

M:6X <&%R=&EC=6QA<BP :70G<R!N;W0 9W5A<F%N=&5E9"!T;R!B92!T:&4-
M" DO+R!A8W1U86P <VEZ92!O9B!T:&4 9&%T86=R86TI.R!T:')O=W, 4F5A
M9$5R<F]R(&]N(&9A:6QU<F4-" EU:6YT(')E8W9&<F]M*$EN=&5R;F5T061D
M<F5S<R!I82P =F]I9"H 8FQO8VLL(&EN="!S:7IE*0T*"7L-" D)<V]C:V%D

M;'0 /2!R96-V9G)O;2AS;V-K970L(&-A<W0H8VAA<BHI(&)L;V-K+"!S:7IE
M+ T*"0D),"P 8V%S="AS;V-K861D<BHI("9S82P )G-A;&5N*3L-" D):68 

M87-T17)R;W(H*2 ]/2!74T%%35-'4TE:12D-" D)"0ER97-U;'0 /2!S:7IE
M("L ,3L-" D)"65L<V4-" D)"0ET:')O=R!N97< 4F5A9$5R<F]R*")S;V-K
M970 9F%I;&5D('1O(')E8V5I=F4 9&%T86=R86TB*3L-" D)?0T*"0EI82YI
M<"YI<&%D9'(N861D<F5S<R ]('-A+G-I;E]A9&1R+G-?861D<CL-" D):6$N
M<&]R=" ](&YT;VAS*'-A+G-I;E]P;W)T*3L-" D)<F5T=7)N(')E<W5L=#L-

M<F4 9G)E<75E;G1L>2P-"B\O('-O('-U8V  86X 86QI87, <V5E;7, ;&]G
 :6-A; T*86QI87, 4W1R96%M4V]C:V5T(%-O8VME=#L`
`
end
Oct 06 2003
parent reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
"Christian Lesage" <christian.lesage.1 agora.ulaval.ca> wrote in message
news:bltn3k$27vo$1 digitaldaemon.com...
 Now, here's my problem. Even using Mike's "socket.d", I can't compile
 Pavel's example "httpget.d". The compiler yields:

 C:\Program Files\DIDE\Projects\httpget\httpget.d(21): cannot create
instance
 of abstract class TCPSocket
There was a recent change in the compiler that disallows instantiation of abstract classes. It means that the code must be fixed. You might find more about it in the docs. Lars Ivar Igesund
Oct 07 2003
parent reply "Christian Lesage" <christian.lesage.1 agora.ulaval.ca> writes:
 There was a recent change in the compiler that disallows instantiation of
 abstract
 classes. It means that the code must be fixed. You might find more about
it
 in
 the docs.
Thanks for replying. I feel like I am closer to the solution. However, the documentation doesn't tell much about "abstract" classes. Yet Another Stupid Question: What's an "abstract" class? How do you differenciate an "abstract" class from a "concrete" one? TCPSocket looks like a "concrete" class to me. It has a polymorphic constructor and a polymorphic member function "connect()". BTW, I post "httpget.d", just in case somebody feeling particularly generous have time to look into the problem... ;) begin 666 HTTPGET.D M+RH-"B J(%-I;7!L:7-T:6, 2%144"!C;&EE;G0 <V%M<&QE('=R:71T96X M:71S(&1O8W5M96YT871I;VX 9F]R(&%N>2!P=7)P;W-E(&ES(&AE<F5B>2!G M<F%N=&5D('=I=&AO=70 9F5E+ T*("H <')O=FED960 =&AA="!T:&4 86)O M=F4 8V]P>7)I9VAT(&YO=&EC92!A<'!E87( :6X 86QL(&-O<&EE<R!A;F0- M"B J('1H870 8F]T:"!T:&%T(&-O<'ER:6=H="!N;W1I8V4 86YD('1H:7, M8W5M96YT871I;VXN("!!=71H;W( ;6%K97, ;F\ <F5P<F5S96YT871I;VYS M(")W=W<N9&EG:71A;&UA<G,N8V]M(CL-"F-O;G-T(&EN="!P;W)T(#T M(&QE;B ]('-P<FEN=&8H<F5Q=65S="P (D=%5" O($A45% O,2XP7&Y(3U-4 M*3L-" D)"6-O=6YT(#T ,#L-" D)?0T*"7T-" D-" EP<FEN=&8H(B4N*G-< :;B(L(&9I;&4I.PD-" ER971U<FX ,#L-"GT` ` end
Oct 07 2003
parent "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
"Christian Lesage" <christian.lesage.1 agora.ulaval.ca> wrote in message
news:bluqpu$q19$1 digitaldaemon.com...
 What's an "abstract" class? How do you differenciate an "abstract" class
 from a "concrete" one? TCPSocket looks like a "concrete" class to me. It
has
 a polymorphic constructor and a polymorphic member function "connect()".
An abstract class is a crossing between an interface and a normal class. The methods can be implemented (but don't have to be). It should be used on classes (usually base classes in a hierarchy) that makes no sense to instantiate, but that it is nice to have some code that is common for all subclasses. abstract has the same meaning in Java, an explanation can be found here: http://java.sun.com/docs/books/tutorial/java/javaOO/abstract.html Lars Ivar Igesund
Oct 07 2003