How do I correctly set up my UdpClient to listen on the multicast address 239.255.255.250:1900 in C# - multicast

I am setting up a small local network with 3 laptops. My goal is to experiment with the UpNP protocol and have the laptops discover each other using UpNP. In order to do this, they need to be able to listen for notifications from each other. As per the protocol, these notifications are sent on multicast address 239.255.255.250:1900. However, I am having a problem setting the laptops up to listen on that address. I am starting just using 1 pc. My PC's IP address is 10.0.0.5.
However, when I try to set up a UdpClient to listen on 239.255.255.250:1900 I get an error saying: "The requested address is not valid in its context".
I have tried just setting it up using this:
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);
UdpClient client = new UdpClient(endpoint);
client.BeginReceive(MessageReceived, null);
I have also tried:
UdpClient client = new UdpClient(Port);
client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));
client.BeginReceive(MessageReceived, null);
But I still get the same error: "The requested address is not valid in its context".
How do I correctly set up my UdpClient to listen on the multicast address 239.255.255.250:1900 ?
Thanks for your help!!!

Ok, after much searching and banging my head on my desk, I've got this thing working. I thought I had it working yesterday, but it only worked on Windows 7 and not on XP..
So, here it goes:
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, Port);
UdpClient client = new UdpClient();
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
client.Client.Bind(localEndPoint);
client.JoinMulticastGroup(IPAddress);
client.MulticastLoopback = true;
Client.BeginReceive(MessageReceived, null);
I sure wish this was documented a bit better, but I guess that's why we get the big bucks $$$.
Thanks StackOverflow for providing such an AWESOME knowledgebase from which to extract this stuff !!

Related

Unity bluetooth communication - implementation

So I have read and tried about everything in order to start a simple bluetooth listener in Unity but with no luck. And couldn't find anyone who managed this.
The main issue is this socket exception:
"SocketException: An address incompatible with the requested protocol was used."
Has anyone successfully implemented bluetooth communication in Unity?
P.S.
I also tried the 32feet library but it gives the same exception when trying to create a new bluetooth listener :
Guid mUUID = new Guid("00001101-0000-1000-8000-00805F9B34FB");
BluetoothListener blueListener = new BluetoothListener(mUUID);

I get Network is unreachable in Java

Good day everyone!
I am making a DHCP Server for a project. I tried it in Windows and it worked. Now, I need to make it work on Linux. I used the same code and it can listen packets coming from port 67. However, every time I am about to send packets to the machine in KVM (Kernel Virtual Machine), I get an error at line containing "datagramsocket.send(response)" saying that Network is Unreachable. Btw, I am using a centOS as host and another centOS as guest machine. Bridge connection and firewall is disabled. How could I fix this problem? I am clueless.
Thanks in advance! :)
I used a dhcp4java API and here's a portion of my code:
if (replypacket != null){
InetAddress add = replypacket.getAddress();
int port = replypacket.getPort();
byte[] buf = replypacket.serialize();
DatagramPacket response = new DatagramPacket(buf, buf.length, add, port);
datagramsocket.send(response);
}

Select IP Addresses which use a specific port

My idea here is create a website where the user is able to click a button which will look into the IP Addresses to see which one is using a certain port, for example:
I want to search for the IP Addresses which are communicating with the localhost that are using the port #3620 (which is obviously being used) and a code will show all the IP Addresses.
My question here is to see if this is possible and if it is, can someone give a brief idea of how this could be done?
For seeing if a port is open check out this:
In C#, how to check if a TCP port is available?
You could even loop over all port numbers for an IP address and check to see what ones are open.
TcpClient tcpClient = new TcpClient();
try
{
tcpClient.Connect("127.0.0.1", 9081);
Console.WriteLine("Port " + 9081+ " Open");
}
catch (Exception)
{
Console.WriteLine("Port " + 9081+ " Closed");
}

PHP + PostFix + Amazon SES + Multiple Domains (transports)

I've decided to post this here and not on serverfault, as the community there is to small and nearly 80% of my questions are unanswered...
So I've got my sever with 3 domains: x.com, y.com and z.com. x.com relays internally, y.com relays internally, and z.com SHOULD relay through amazon SES.
Right now, x and y.com mail correctly internally, but I need z.com to relay through SES.
So, my config so far in main.cf:
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_transport
domainz_sasl_auth_enable = yes
domainz_sasl_security_options = noanonymous
domainz_sasl_password_maps = hash:/etc/postfix/sas2_passwd
domainz_use_tls = yes
domainz_tls_security_level = encrypt
domainz_tls_note_starttls_offer = yes
domainz_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
and in my master.cf, I've appended a unix channel above the default smtp:
domainz unix - - n - 1 smtp
smtp inet n - n - - smtpd
and in my sender_transport I have
#domainZ.com domainz:
1. Where do I enter the ses smtp of "email-smtp.us-east-1.amazonaws.com". I assume we need to hit "domainz:" so we can pass the correct sasl data to it.
2. Keep in mind that this is mail going out from the server, not in, so that's why I didn't set a transport_map.
This is the error I'm getting when pushing out mail from #domainz:
"status=bounced (Host or domain name not found. Name service error for name=domainz type=AAAA: Host not found)"; so before we can even get to amazon's SES host, I'm having an issue at the transport level that I can't seem to figure out.
Thanks,
Mike
After nearly 24 hours of trying to solve this, I finally figured it out. I hope this helps whomever is looking to use this same method and doesn't have to go through the pain I just went through!
So in my example above, domain x + y relayed through virtual aliases. For z we must use a transport, in this case it was a sender_dependent_relayhost_maps transport, so I can grab the sender and relay them through amazon SES.
In main.cf, regardless of smtp/unix-socket, we straight up use SES standards:
smtp_sasl_auth_enable=yes
smtp_sasl_security_options=noanonymous
smtp_sasl_password_maps=hash:/etc/postfix/sas
smtp_use_tls=yes
smtp_tls_security_level=encrypt
smtp_tls_note_starttls_offer=yes
smtp_tls_CAfile=/etc/ssl/certs/ca-bundle.crt
In sender_dependent_relayhost_maps we use:
#domainz.com [email-smtp.us-east-1.amazonaws.com]:25
The smtp_sasl_password_maps file stores the matching relay's user:key.
And that's it!

WinCE: 10053 error during connect

I wrote a Bluetooth client program for a wince 4.2 device. The device discovery works fine. However, when I attempt to connect to a PC, the connect function immediately returns with error code 10053. The connection request was being processed by the PC with a prompt to enter the authentication code but the wince device doesn’t seem to wait.
What could be causing this issue? I am using the following steps (removed error handling for simplicity):
WSAStartup(..)…////was successful.
SOCKET m_Socket =Socket (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); //was successful.
SOCKADDR_BTH sClinet;
memset (&sClinet, 0, sizeof(sClinet));
sClinet.addressFamily = AF_BTH;
sClinet.btAddr = btd.btaddr; ; //BT_ADDR of the PC obtained via Device Discovery..
sClinet.port = BT_PORT_ANY; //I did try 0, did not help!
sClinet.serviceClassId = RFCOMM_PROTOCOL_UUID;
int nConErr = connect (m_Socket, (SOCKADDR *)&sClinet, sizeof(sClinet));
nConErr returns 10053 immediately. It doesn’t even wait, even though the PC recognized the connection and prompted a message to enter the PIN for authentication.
From what you are describing it looks like it is a pairing/authentication problem. You should consider in using also setsockopt function: http://msdn.microsoft.com/en-us/library/ms863347.aspx
You should try to use SO_BTH_AUTHENTICATE option which according to MSDN:
On connected socket, triggers authentication. On not connected socket, forces authentication on connection. For incoming connection this means that connection is rejected if authentication cannot be performed.
So before calling connect function you should set options to your socket.

Resources