www.digitalmars.com         C & C++   DMDScript  

D - socket.d update

reply Vathix <vathix dprogramming.com> writes:
Resolves hosts now, and made other changes.

http://www.dprogramming.com/socket.php


-- 
Christopher E. Miller
Mar 18 2004
parent reply Vathix <vathix dprogramming.com> writes:
Just wrote the Socket stream class attached. readLine/readLineW safely 
don't use ungetc. Here's an example of Walter's HTML ;)


import socket, socketstream;

int main()
{
    Socket sock = new Socket(AddressFamily.INET, SocketType.STREAM, 
ProtocolType.IP);
    sock.connect(new InternetAddress("www.digitalmars.com", 80));
    SocketStream ss = new SocketStream(sock);

    ss.writeString("GET /d/intro.html HTTP/1.1\r\n"
       "Host: www.digitalmars.com\r\n"
       "\r\n");

    while(ss.readLine().length) {} //skip header
    while(!ss.eof())
    {
       char[] line;
       printf("%.*s\n", ss.readLine());
    }

    return 0;
}


-- 
Christopher E. Miller
Mar 19 2004
next sibling parent reply larry cowan <larry_member pathlink.com> writes:
In article <c3f4c4$25m8$1 digitaldaemon.com>, Vathix says...
 Just wrote the Socket stream class attached. readLine/readLineW safely 
don't use ungetc. Here's an example of Walter's HTML ;)
Using what socket.d?
Mar 19 2004
parent Vathix <vathix dprogramming.com> writes:
larry cowan wrote:
 In article <c3f4c4$25m8$1 digitaldaemon.com>, Vathix says...
 
Just wrote the Socket stream class attached. readLine/readLineW safely 
don't use ungetc. Here's an example of Walter's HTML ;)
Using what socket.d?
Mine at http://www.dprogramming.com/socket.php -- I've added socketstream.d to the zip as well. -- Christopher E. Miller
Mar 19 2004
prev sibling parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
Looks good... and could be exactly what I'm needing for a 
project-on-hold of mine.  It hinges on a decent socket module (among 
other things) and I was dreading the prospect of coding one up.  Might 
not have to now.  :)

Except... Attempting to compile your example yields (for me anyhow):

socket.obj(socket)
  Error 42: Symbol Undefined _gethostbyname 4
socket.obj(socket)
  Error 42: Symbol Undefined _gethostbyaddr 12
socket.obj(socket)
  Error 42: Symbol Undefined _inet_addr 4
socket.obj(socket)
  Error 42: Symbol Undefined _inet_ntoa 4
socket.obj(socket)
  Error 42: Symbol Undefined _ioctlsocket 12
socket.obj(socket)
  Error 42: Symbol Undefined _getsockopt 20
socket.obj(socket)
  Error 42: Symbol Undefined _bind 12
socket.obj(socket)
  Error 42: Symbol Undefined _connect 12
socket.obj(socket)
  Error 42: Symbol Undefined _WSAGetLastError 0
socket.obj(socket)
  Error 42: Symbol Undefined _listen 8
socket.obj(socket)
  Error 42: Symbol Undefined _accept 12
socket.obj(socket)
  Error 42: Symbol Undefined _shutdown 8
socket.obj(socket)
  Error 42: Symbol Undefined _closesocket 4
socket.obj(socket)
  Error 42: Symbol Undefined _getpeername 12
socket.obj(socket)
  Error 42: Symbol Undefined _getsockname 12
socket.obj(socket)
  Error 42: Symbol Undefined _send 16
socket.obj(socket)
  Error 42: Symbol Undefined _sendto 24
socket.obj(socket)
  Error 42: Symbol Undefined _recv 16
socket.obj(socket)
  Error 42: Symbol Undefined _recvfrom 24
socket.obj(socket)
  Error 42: Symbol Undefined _setsockopt 20
socket.obj(socket)
  Error 42: Symbol Undefined _WSAStartup 8
socket.obj(socket)
  Error 42: Symbol Undefined _WSACleanup 0
socket.obj(socket)
  Error 42: Symbol Undefined _socket 12
--- errorlevel 23

So either my std.c.windows.windows is fudged, or I've missed something 
somewhere.  Tips?

-C. Sauls
-Invironz
Mar 20 2004
parent reply Vathix <vathix dprogramming.com> writes:
C. Sauls wrote:
 Looks good... and could be exactly what I'm needing for a 
 project-on-hold of mine.  It hinges on a decent socket module (among 
 other things) and I was dreading the prospect of coding one up.  Might 
 not have to now.  :)
 
 Except... Attempting to compile your example yields (for me anyhow):
 
 socket.obj(socket)
  Error 42: Symbol Undefined _gethostbyname 4
 socket.obj(socket)
  Error 42: Symbol Undefined _gethostbyaddr 12
 socket.obj(socket)
  Error 42: Symbol Undefined _inet_addr 4
 socket.obj(socket)
  Error 42: Symbol Undefined _inet_ntoa 4
 socket.obj(socket)
  Error 42: Symbol Undefined _ioctlsocket 12
 socket.obj(socket)
  Error 42: Symbol Undefined _getsockopt 20
 socket.obj(socket)
  Error 42: Symbol Undefined _bind 12
 socket.obj(socket)
  Error 42: Symbol Undefined _connect 12
 socket.obj(socket)
  Error 42: Symbol Undefined _WSAGetLastError 0
 socket.obj(socket)
  Error 42: Symbol Undefined _listen 8
 socket.obj(socket)
  Error 42: Symbol Undefined _accept 12
 socket.obj(socket)
  Error 42: Symbol Undefined _shutdown 8
 socket.obj(socket)
  Error 42: Symbol Undefined _closesocket 4
 socket.obj(socket)
  Error 42: Symbol Undefined _getpeername 12
 socket.obj(socket)
  Error 42: Symbol Undefined _getsockname 12
 socket.obj(socket)
  Error 42: Symbol Undefined _send 16
 socket.obj(socket)
  Error 42: Symbol Undefined _sendto 24
 socket.obj(socket)
  Error 42: Symbol Undefined _recv 16
 socket.obj(socket)
  Error 42: Symbol Undefined _recvfrom 24
 socket.obj(socket)
  Error 42: Symbol Undefined _setsockopt 20
 socket.obj(socket)
  Error 42: Symbol Undefined _WSAStartup 8
 socket.obj(socket)
  Error 42: Symbol Undefined _WSACleanup 0
 socket.obj(socket)
  Error 42: Symbol Undefined _socket 12
 --- errorlevel 23
 
 So either my std.c.windows.windows is fudged, or I've missed something 
 somewhere.  Tips?
 
 -C. Sauls
 -Invironz
For windows, you'll have to link with ws2_32.lib, which is in my downloads section if you need it. -- Christopher E. Miller
Mar 20 2004
parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
Marry me?  :D  That did it... I figured it was a forehead-slapper.  I'll 
let you know how it performs for me.

-C. Sauls
-Invironz
Mar 20 2004
parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
Hmm.. now if only SockeStream.readLine() didn't block when there's no 
data from the socket... has to be a way to set that up, or should I 
thread it out... hmm.  (Haven't touched sock code in forever, having to 
re-learn everything.)

-C. Sauls
-Invironz
Mar 20 2004
parent reply "Phill" <phill pacific.net.au> writes:
Isnt there a "blocking" bool there in the socket
class? Maybe that could do the trick?

Phill

"C. Sauls" <ibisbasenji yahoo.com> wrote in message
news:c3i402$16p5$1 digitaldaemon.com...
 Hmm.. now if only SockeStream.readLine() didn't block when there's no
 data from the socket... has to be a way to set that up, or should I
 thread it out... hmm.  (Haven't touched sock code in forever, having to
 re-learn everything.)

 -C. Sauls
 -Invironz
Mar 20 2004
next sibling parent reply "Phill" <phill pacific.net.au> writes:
or would you believe blocking bit?.


"Phill" <phill pacific.net.au> wrote in message
news:c3ida2$1m56$1 digitaldaemon.com...
 Isnt there a "blocking" bool there in the socket
 class? Maybe that could do the trick?

 Phill

 "C. Sauls" <ibisbasenji yahoo.com> wrote in message
 news:c3i402$16p5$1 digitaldaemon.com...
 Hmm.. now if only SockeStream.readLine() didn't block when there's no
 data from the socket... has to be a way to set that up, or should I
 thread it out... hmm.  (Haven't touched sock code in forever, having to
 re-learn everything.)

 -C. Sauls
 -Invironz
Mar 20 2004
parent reply C <dont respond.com> writes:
Hehe 8).  You'll prolly have to set a timeout , or use asynch sockets . =
A =

listener thread is usually the route i take with blocking sockets.

C

On Sun, 21 Mar 2004 08:35:02 +1100, Phill <phill pacific.net.au> wrote:

 or would you believe blocking bit?.


 "Phill" <phill pacific.net.au> wrote in message
 news:c3ida2$1m56$1 digitaldaemon.com...
 Isnt there a "blocking" bool there in the socket
 class? Maybe that could do the trick?

 Phill

 "C. Sauls" <ibisbasenji yahoo.com> wrote in message
 news:c3i402$16p5$1 digitaldaemon.com...
 Hmm.. now if only SockeStream.readLine() didn't block when there's =
no
 data from the socket... has to be a way to set that up, or should I=
 thread it out... hmm.  (Haven't touched sock code in forever, havin=
g =
 to
 re-learn everything.)

 -C. Sauls
 -Invironz
-- = D Newsgroup.
Mar 20 2004
parent "C. Sauls" <ibisbasenji yahoo.com> writes:
The specs for the project I'm thinking of including it in calls for a 
threaded socket system anyhow, so that's the route I'm likely to go.  I 
just thought it might be nice to be able to avoid it at times.

-C. Sauls
-Invironz

C wrote:
 Hehe 8).  You'll prolly have to set a timeout , or use asynch sockets . 
 A listener thread is usually the route i take with blocking sockets.
 
 C
Mar 21 2004
prev sibling parent reply Vathix <vathix dprogramming.com> writes:
Phill wrote:

 Isnt there a "blocking" bool there in the socket
 class? Maybe that could do the trick?
 
 Phill
Yes, but you can't call receive() on a nonblocking socket unless you've been notified of readability by select(). I think SocketStream will always only be for blocking sockets. I have ideas for a nonblocking alternative, with events and built in timers. -- Christopher E. Miller
Mar 20 2004
parent "C. Sauls" <ibisbasenji yahoo.com> writes:
Now using events is an interesting idea...  I could envision working 
that paradigm into this project if you got it working.. at least maybe 
for the sockets opened by the internal scripting engine, while threading 
the hardcoded socket bindings...

-C. Sauls
-Invironz

Vathix wrote:

 Phill wrote:
 
 Isnt there a "blocking" bool there in the socket
 class? Maybe that could do the trick?

 Phill
Yes, but you can't call receive() on a nonblocking socket unless you've been notified of readability by select(). I think SocketStream will always only be for blocking sockets. I have ideas for a nonblocking alternative, with events and built in timers.
Mar 21 2004