Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8625357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:45:54+00:00 2026-06-12T07:45:54+00:00

I have created a toy example for a UDP echo client and server. However,

  • 0

I have created a toy example for a UDP echo client and server. However, I do not receive the reply from the server and I wonder what am I doing wrong.

Client:

#!/usr/bin.rdmd
import std.stdio;
import std.socket;
import std.string;
import std.conv;
import std.random;
import std.outbuffer;

int main(string[] args) {
  if (args.length != 3) {
    writefln("usage: %s <server host> <port>",args[0]); 
    return 0;
  }

  auto s = new UdpSocket();

  auto addr = new InternetAddress(args[1], to!ushort(args[2]));
  s.connect(addr);
  scope(exit) s.close();

  for (int i = 0; i < 1000; i++){
    auto r = uniform(int.min,int.max);
    auto send_buf = new OutBuffer();

    send_buf.write(r);

    s.send(send_buf.toBytes());

    ubyte[r.sizeof] recv_buf;
    s.receive(recv_buf);

    assert(r == *cast(int*)(send_buf.toBytes().ptr));
  }



  return 0;
}

Server:

#!/usr/bin.rdmd
import std.stdio;
import std.socket;
import std.string;
import std.conv;

int main(string[] args) {
  if (args.length != 2) {
    writefln("usage: %s <port>",args[0]); 
    return 0;
  }

  auto s = new UdpSocket();

  auto addr = new InternetAddress("localhost", to!ushort(args[1]));
  s.bind(addr);

  while (true){
    ubyte[int.sizeof] recv_buf;
    s.receive(recv_buf);

    writefln("Received: %s\n",recv_buf);

    s.send(recv_buf);


  }

  writeln("sent");

  return 0;
}

If you execute the programs you will see that the client hangs in receive, while the server has already sent the reply.

Do you know what am I doing wrong?

BTW, What is the best resource for network programming in D?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:45:55+00:00Added an answer on June 12, 2026 at 7:45 am

    The UDP socket on the server is not “connected”, so you cannot use send. It probably returned an error message that you didn’t check. On the server, use receiveFrom with sendTo to reply to a message.

    Note that while UDP is a connectionless protocol, the socket API supports the concept of a connected UDP socket, which is merely the socket library remembering the target address for when you call send. It will also filter out messages not coming from the connected address when calling receive. Connected sockets are usually a bad fit for UDP server programs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created a very simple nested loop example and am struggling to write
I have created a PHP-script to update a web server that is live inside
have created a mobile site for my client www.-leeds-united-fans.co.uk and the problem is when
I have created a QWidget with a bunch of QToolButtons in it and I
I have created some JQuery that will expand a div 'popup' on hover and
I have created a JSP / servlets application running in Tomcat 7. It runs
I have created an EDMX in visual studio 2010 SP1. It has been built
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a custom post type named People. I have created a page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.