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

How do I wrap a primitive data type like int to uint8_t?
Can Range.Value2 & Range.Formula have different values in C#, not VBA?
AND Operator cannot work with bool and string
C# Load/Unload plugins
Visual Studio 2008 not loading symbols when debugging a .DMP
Need emergency help with dw20.exe process? [closed]
Making scribbles on a monochrome image
Covariant instance types on open instance delegates
AS3 Typed Objets Serialization to C# Hashtables and back
How to get host domain from asp.net
I'm validating XML against XSD in Windows Forms using C# .NET and it's giving me the error “Please Suggest the fix”
how to Create “Keep Alive” for a chat app?
AT Command for receiving automatic SMS notification
NSAutoReleasePool and async functions
Apriori algorithm explanation
image upload and preview in mvc 2

Categories

HOME
azure-active-directory
webvr
aix
opencv4android
reference
cryengine
assign
squeak
mediarecorder
angularjs-directive
zabbix
ejb-3.0
jcodemodel
jpql
captcha
responsive
ringcentral
udeploy
summernote
jq
klipfolio
google-drive-android-api
infinite-loop
quality-center
ckeditor4.x
knapsack-problem
osgi-bundle
sphinx4
mobile-development
multilanguage
login-required
urhosharp
certbot
pymunk
device-driver
realloc
form-fields
lex
redbean
directadmin
test-kitchen
web-technologies
mef
cloudconvert
runtime-permissions
dotnet-cli
audio-fingerprinting
aws-rds
selection-sort
androiddesignsupport
programming-pearls
senti-wordnet
trusted-computing
tsc
catalyst
sqlproj
portaudio
racket-student-languages
mac-app-store
consolidation
syslog4j
qtruby
shtml
database-administration
nugetgallery
hana-sql-script
fadein
windows-phone-8-emulator
pdcurses
autopep8
nexusdb
esri-arc-engine
fiware-health
conditional-comments
growl
zoneminder
visual-c#-express-2010
atg-dynamo
webshim
nomachine
scidb
8-puzzle
mobile-robots
kohana-orm
architectural-patterns
phone-state-listener
motorola-droid
ruby-1.9
opendir
funambol
symfony-1.2
service-layer
method-call
nbehave
appointment
onresize

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