473,796 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UDP Broadcast recieve

I can't figure out why my code does not recieve the message. The only
message that it receives is the one going out from my machine. I am
suppose to send out a message to a server. Upon receiving that message
on the server side the server is suppose to send a message back. I
can't get my app to receive that message. It only receives the one
being sent out by my machine. I know that the server is sending out a
message because there is another app in vb that receives the message.
Here is my code:

private constructor()
{
iepSend = new IPEndPoint(IPAd dress.Broadcast , UDP_PORT);
epSend = (EndPoint)iepSe nd;

iepRx = new IPEndPoint(IPAd dress.Any, UDP_PORT);
epRx = (EndPoint)iepRx ;

m_SocketUDP = new Socket(AddressF amily.InterNetw ork, SocketType.Dgra m,
ProtocolType.Ud p);
m_SocketUDP.Set SocketOption(So cketOptionLevel .Socket,
SocketOptionNam e.Broadcast, 1);
m_SocketUDP.Set SocketOption(So cketOptionLevel .Socket,
SocketOptionNam e.ReuseAddress, 1);
m_SocketUDP.Con nect(epSend);

udpRxSocket = new Socket(iepRx.Ad dressFamily, SocketType.Dgra m,
ProtocolType.Ud p);
udpRxSocket.Set SocketOption(So cketOptionLevel .Socket,
SocketOptionNam e.ReuseAddress, 1);
udpRxSocket.Set SocketOption(So cketOptionLevel .Socket,
SocketOptionNam e.ReceiveTimeou t, 5000);
udpRxSocket.Bin d(iepRx);

SetupReceiveCal lbackUDP()
}

private void SetupReceiveCal lbackUDP()
{
AsyncCallback receiveData = new AsyncCallback(O nReceiveData);
udpRxSocket.Beg inReceiveFrom(b uffer, 0, buffer.Length,
SocketFlags.Non e, ref epRx, receiveData, udpRxSocket);
}

private void OnReceiveData(I AsyncResult ar)
{
Socket socket = (Socket)ar.Asyn cState;

try
{
int nBytesRec = socket.EndRecei veFrom(ar, ref epRx);
if(nBytesRec > 0)
{
string Received = Encoding.ASCII. GetString(buffe r, 0, nBytesRec);
//Received += socket.RemoteEn dPoint.ToString ();
WriteOutput("Re ceived Data: " + Received);
SetupReceiveCal lbackUDP();
}
}
catch(Exception e)
{
WriteOutput("Er ror. "+ e.Message);
}
}

Anyone know whats wrong?

Dec 19 '05 #1
1 2011
Dave,
I can't figure out why my code does not recieve the message.


Unfortunately I don't have the time to review your code, but two things come
into mind architecture-wise: firewall settings and network errors.

Years ago I wrote a simple system to broadcast UDP messages to a local
subnet. This solution worked well when the 10 MB Ethernet network wasn't
busy, but when there were lots of traffic, those little UDP messages simply
were "missing in action". The same thing might happen to you.

Also, if it only happens that the server sees your client's messages but not
the other way around, check the (desktop)firewa ll settings on the server
(for outbound UDP blocking) and on your client (for incoming blocks).

Hope this helps.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethi s.dystopia.fi
http://www.saunalahti.fi/janij/
Dec 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10328
by: pekspro | last post by:
I need some code that gets the address from a server. I read somewhere that you could do this by starting some broadcast server using UDP. The client should send an broadcast message, and when the server answering the client gets the address. But how do I implement this? I did this simple quick-hack: Server: Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
2
4892
by: K.K. | last post by:
I am writing program that will recieve or sent data to selected port (users can select which port they want to recieve or sent) but I don't know how or whick object I can use.
2
1482
by: Jody L. Whitlock | last post by:
I'm kinda stumped at the moment, so... Here's what I'm looking to do: I have a ClientSocket, and I would like to free-thread the recieve end of it. I tried a delegate, but that won't fire. I'm thinking of using a networkstream, but can't really find anything on that. The purpose behind this is becuase my current solution is dropping bytes. I will post my class here....
0
1120
by: Dave | last post by:
I can't figure out why my code does not recieve the message. The only message that it receives is the one going out from my machine. I am suppose to send out a message to a server. Upon receiving that message on the server side the server is suppose to send a message back. I can't get my app to receive that message. It only receives the one being sent out by my machine. I know that the server is sending out a message because there is...
2
2593
by: Dave | last post by:
Does anyone have an example of how to receive a connectionless(udp) broadcast in c#. I have tried everything i can possibly think of and it won't recieve the message. I know that the message is coming in and that its not being blocked because there is another app on my machine that is getting the message. Please help.
7
2747
by: sreehari | last post by:
Hi All, I have this problem, I have developed a Master - Slave kinda appliacation , were the slave is generally a device.when i broadcast a message from my application, the Device seems to recieve the message and responds correctly, and replies with a broadcast frame. Here is where i face the problem, what happens is that my application seems to Time out even if Ethereal ( Network Sniffer ) detects and shows all the frames that were
3
3657
Sagittarius
by: Sagittarius | last post by:
Hi there. I have a problem concerning an UDP socket in C++ (Winsock). The next paragraphs is merely to explain the system I am working on. If U want to skip it, I have marked the question in bold below it. I have a pc, connected to a network of boards, all connected in a ring, all having their own unique IP adresses. As it is now, I send messages to the network of boards via broadcast, so all the boards gets the message. All the...
2
3925
by: ericlangland | last post by:
Hi, I have a small managed code application (windows forms) that executes on startup and immidiatly minimizes to the system tray. It launches and shows the form when I double click it's small icon in the system tray. So far so good. I'd like for the app to maximize outside of the system tray when the Windows + ? combination keys are selected. It seems that I can catch keystrokes when the form is showing but when minimized(Hide()) it in...
1
2050
by: 4project | last post by:
i wanted to design a user interface such that i can handle all the incoming and outgoing calls , also send and recieve sms. I know that for sure that we can 1a .call 2a send sms but not sure if we can 1b. recieve a call 2b., receieve an sms.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.