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

Background worker c# stop worker - immediately (include Thread.Sleep in DoWork)
Web Api 2.0 OAuth 2.0 Testing with Postman
IMobileServiceSyncTable Incremental PullAsync - No Results
How to abtract DBMS requests in a .NET program, while being able to alter database during runtime
Anonymous method in static class is non-static? How to invoke it?
Upload file to Google Drive with C#
Can title of browser be changed in selenium c#?
Having an issue while binding data to gridview
How can i get a collection of child elements - query returns null using Xdocument
Database definition for Identity User - dbo.AspNetUsers and dbo.Users
c# select query to Oracle database throws “Custom type mapping for … is not specified or is invalid”
More efficient UI Overlay in 2D Unity game
CRUD filtering/sorting doesnt work in asp.net
What argument should I use with SqlFunctions.DateName to get the month like “MM”?
Diagonal match in Connect 4
DataTrigger storyboard not firing WPF on PropertyValueChange

Categories

HOME
c#
logging
autohotkey
ssms
url
cors
postgresql-9.3
window.open
blob
django-middleware
watson-iot
singleton
squeak
ubuntu-14.04
spring-data-solr
openbsd
jpql
camunda
tmux
jsfiddle
internet-explorer-7
jquery-easyui
alert
project-structure
serenity-js
wai-aria
rvm
prepros
launchd
mobile-development
apm
drawrect
key-bindings
kubectl
scene7
unity3d-5
sampling
rtsp
redhat-brms
usernotifications
file-conversion
delphi-xe
android-graphview
android-doze-and-standby
line-endings
xmldom
spring-cloud-bus
flask-socketio
px4
jcifs
richtext
nservicebus6
selection-sort
codesniffer
spring-cloud-aws
cedar-bdd
blackberry-webworks
android-tabs
racket-student-languages
dimensionality-reduction
ldd
git-push
require-handlebars
git-cherry-pick
airwatch
aws-kms
web-optimization
methodology
github-for-mac
play-json
autoscaling
callfire
eggplant
web-standards
photogrammetry
log-analysis
perfect-scrollbar
data-quality-services
jad
xmla
fedena
fxmlloader
unityvs
worklight-appcenter
pidgin
nodeunit
mongoid4
carrier
db2-connect
misfire-instruction
myrrix
mobile-robots
record-locking
msbuild-task
feincms
big-endian
databus
aspmenu-control
sup
diazo
wxperl
discussion-board
gmagick
noise-reduction
system-analysis
rpxnow
vista64
tracd

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