Sending UDP packets via the internet and between processes?

Dustin Keeting dksdsfd at gmail.com
Sat May 12 09:29:43 UTC 2018


I'm setting up two applications, a client and a server, that will 
exchange some data back and forth. The server may be on the same 
machine as the client, or it may not be, or there might be 
multiple clients which may or may not be on the same machine. 
Both applications will be running other code and I'd like them to 
be able to access a list of received packets rather than waiting 
for them to come in.

What do I need to do to set this up? This is as far as I've got:

         ushort port = 3000;

	auto sender = new UdpSocket();
	sender.blocking = false;
	auto address = new InternetAddress(port);
	sender.bind(address);

	ubyte[Packet.sizeof] bytes;
	Packet* packet = cast(Packet*)bytes.ptr;
         //not sure how to convert a struct to big endian easily?

	sender.send(bytes);

I'm not really sure how to receive sent bytes or if I need to put 
in ip addresses to make it work online? I've looked at a couple 
of examples and I've gotten some html to work by accessing a 
localhost port, but I've always struggled with networking, so if 
someone can help explain how I'm meant to connect sockets that 
may be online or on the same machine... that would be a big help!


More information about the Digitalmars-d-learn mailing list