473,465 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Create 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(IPAddress.Broadcast, UDP_PORT);
epSend = (EndPoint)iepSend;

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

m_SocketUDP = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
m_SocketUDP.SetSocketOption(SocketOptionLevel.Sock et,
SocketOptionName.Broadcast, 1);
m_SocketUDP.SetSocketOption(SocketOptionLevel.Sock et,
SocketOptionName.ReuseAddress, 1);
m_SocketUDP.Connect(epSend);

udpRxSocket = new Socket(iepRx.AddressFamily, SocketType.Dgram,
ProtocolType.Udp);
udpRxSocket.SetSocketOption(SocketOptionLevel.Sock et,
SocketOptionName.ReuseAddress, 1);
udpRxSocket.SetSocketOption(SocketOptionLevel.Sock et,
SocketOptionName.ReceiveTimeout, 5000);
udpRxSocket.Bind(iepRx);

SetupReceiveCallbackUDP()
}

private void SetupReceiveCallbackUDP()
{
AsyncCallback receiveData = new AsyncCallback(OnReceiveData);
udpRxSocket.BeginReceiveFrom(buffer, 0, buffer.Length,
SocketFlags.None, ref epRx, receiveData, udpRxSocket);
}

private void OnReceiveData(IAsyncResult ar)
{
Socket socket = (Socket)ar.AsyncState;

try
{
int nBytesRec = socket.EndReceiveFrom(ar, ref epRx);
if(nBytesRec > 0)
{
string Received = Encoding.ASCII.GetString(buffer, 0, nBytesRec);
//Received += socket.RemoteEndPoint.ToString();
WriteOutput("Received Data: " + Received);
SetupReceiveCallbackUDP();
}
}
catch(Exception e)
{
WriteOutput("Error. "+ e.Message);
}
}

Anyone know whats wrong?

Dec 19 '05 #1
1 1997
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)firewall 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***@removethis.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
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...
2
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
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...
0
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...
2
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...
7
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...
3
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...
2
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...
1
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.