Advertisement
apcehypo

Listen&Eject: Broadcaster

Mar 1st, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.77 KB | None | 0 0
  1. import std.stdio;
  2. import std.socket;
  3. import std.conv;
  4. import std.process;
  5. import core.thread;
  6.  
  7. void main(string[] argv) {
  8.   if (argv.length == 2) { argv ~= "4455"; }
  9.   if (argv.length != 3) {
  10.     writefln("Usage: %s <server host> <port>", argv[0]);
  11.     return;
  12.   }
  13.   ushort port = parse!ushort(argv[2]);
  14.   auto addr = new InternetAddress(argv[1], port);
  15.   auto s = new UdpSocket();
  16.   writefln("Sending datagrams to %s:%s", addr.toAddrString, port);
  17.  
  18.   while (true){
  19.     write("\b",progressChar);; stdout.flush;
  20.     s.sendTo(null, addr);
  21.     core.thread.Thread.sleep(dur!("seconds")(3));
  22.   }
  23. }
  24.  
  25. char progressChar() {
  26.   static char[] chars = [ '-', '\\', '|', '/', ];
  27.   static int index = 0;
  28.   if (index == chars.length) index = 0;
  29.   return chars[index++];
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement