c#


C# UdpClient not receiving packet seen by wireshark


I'm implementing a udp discovery protocol wherein I broadcast a message to my local network and receive a message from custom hardware (or a simulator for the hardware) or multiple responses depending on how many instances are present on the network.
I have the broadcast working fine, however the receive portion has some issues: I see the broadcasts I send, but never the hardware responses. I know that the hardware is sending the broadcasts because I see them come in on wireshark when I monitor the traffic on that port.
What am I doing wrong?
IPEndPoint receiveIpEndPoint = new IPEndPoint(IPAddress.Any, 777);
private List<string> FindIPs() {
string message = "{\"TCS\":{\"IP\":\"" + GetLocalIPAddress().ToString() + "\", \"Port\":777}}";
byte[] tempBytes = ASCIIEncoding.ASCII.GetBytes(message);
IPEndPoint broadcastIpEndPoint = new IPEndPoint(IPAddress.Broadcast, 777);
// list of UdpClients to send
List<UdpClient> sendClients = new List<UdpClient>();
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces()) {
if ((!networkInterface.Supports(NetworkInterfaceComponent.IPv4)) ||
(networkInterface.OperationalStatus != OperationalStatus.Up)) {
continue;
}
IPInterfaceProperties adapterProperties = networkInterface.GetIPProperties();
UnicastIPAddressInformationCollection unicastIPAddresses = adapterProperties.UnicastAddresses;
IPAddress ipAddress = null;
foreach (UnicastIPAddressInformation unicastIPAddress in unicastIPAddresses) {
if (unicastIPAddress.Address.AddressFamily != AddressFamily.InterNetwork) {
continue;
}
ipAddress = unicastIPAddress.Address;
break;
}
if (ipAddress == null) {
continue;
}
UdpClient sendClient = new UdpClient(new IPEndPoint(ipAddress, 0));
sendClients.Add(sendClient);
}
var udpreceive = new UdpClient(receiveIpEndPoint);
udpreceive.BeginReceive(new AsyncCallback(ProcessUDPResponse), udpreceive);
Log(message, LogManager.GetLogger("Sent UDP broadcast"));
foreach (var udp in sendClients) {
udp.EnableBroadcast = true;
udp.Send(tempBytes, tempBytes.Length, broadcastIpEndPoint);
}
while(addresses.Count < 1) {
}
return addresses;
}
private void ProcessUDPResponse(IAsyncResult result) {
UdpClient udp = result.AsyncState as UdpClient;
string returnData = Encoding.ASCII.GetString(udp.EndReceive(result, ref receiveIpEndPoint));
Console.WriteLine("************** " + returnData.ToString());
if (returnData.Contains("MAC")) {
addresses.Add(receiveIpEndPoint.Address.ToString());
}
udp.BeginReceive(new AsyncCallback(ProcessUDPResponse), udp);
}

Related Links

Check for Square Brackets in Datatable.Select
Unable to read from stream in C#
Ranorex Passing Array as Parameter
Deleting null items from an ObservableCollection
How to convert decimal(integer) to binary, working with the binary and then convert it back to decimal in C#
Ensuring Thread-Safety On Static Methods In C#
Async method never returns [duplicate]
C# and ReSharper: Checking an object's type
How to pass more parametrers than used in an oracle query in ODP.NET without getting exception?
How to: HTTP GET and POST request with parameters in Win 8 modern app using C# and XAML
Word Interop Catch Document Edit Event
MVC best practises for Create functions in Controllers [closed]
C# create temporary url to receive HTTP request
WCF (ServiceHost) is not reachable while created from outside via Activator.CreateInstance
browser Unique id asp.net
How to pass values to javascript from c# to ascx page

Categories

HOME
readdir
conceptual
livecharts
redhawksdr
ubuntu-14.04
coordinates
esxi
comments
phpexcel
gcloud
point-of-sale
derby
javascript-debugger
yui
appsettings
dat.gui
web-worker
airbnb
project-structure
mattermost
infinite-loop
scalatest
nsopenpanel
adobe-captivate
checkmarx
intermec
jcr
epub
jsonapi-resources
webspeech-api
wit-ai
certbot
libconfig
latency
usernotifications
contenteditable
reqif
qtwebkit
emacs24
ear
codesniffer
tsc
ios-keyboard-extension
android-xmlpullparser
vitamio
system-integration
aws-kms
methodology
wonderware
commercetools
php-gd
page-flipping
log4cxx
openhab
properties-file
tess4j
cl.exe
backtrace
dojox.grid
gnip
windows-search
selenium-grid2
fscanf
xpand
banana-pi
new-operator
fastcgi-mono-server
xtify
netbeans-plugins
google-voice
8-puzzle
octokit
caroufredsel
nsnumber
source-depot
magicsuggest
mmo
ntdll
idoc
xcode4.6.3
optimistic-concurrency
cgaffinetransform
mcpd
virtual-printer
norton
pitch-shifting
datadude
data-formats
ffdshow
onresize
disk-based

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App