std.socket with GDC

Joseph Bell josephabell at tx.rr.com
Tue Jan 23 22:09:52 PST 2007


Howdy.

I'm currently using gdc (should I switch to dmd? What would that provide 
me?)

and the following should be functional but it isn't:

I create a UDP socket, Address family is INET, I create the address as 
my loopback on the given port.

I bind.  Blocking returns true, isAlive returns true.  So I'm blocking, 
I'm alive, and then I hit receiveFrom which should block until I have 
something to read.  That falls right through.  :-(

I searched high and low for working examples of client-server programs 
(you can refer me to those too if they exist) to no avail.  I sure hope 
this is a boneheaded mistake on my part.

Thanks for any insight,
Joe

import std.socket;
import std.stdio;

void main() {

   UdpSocket       sock     = new UdpSocket(AddressFamily.INET);
   InternetAddress sockAddr = new InternetAddress("127.0.0.1", 3001);

   writefln("%s", sockAddr.toString());

   sock.bind(sockAddr);

   if (sock.blocking()) {
     writefln("Socket is blocking");
   }
   if (sock.isAlive()) {
     writefln("Socket alive");
   }

   ubyte[] buf;
   Address receiveAddress;
   int bytes;

   bytes = sock.receiveFrom(buf, receiveAddress);

   if (bytes) {
     writefln("Received %d bytes", bytes);
   } else {
     writefln("Error or nothing received");
   }

}



More information about the Digitalmars-d mailing list