471,627 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

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,
m_SocketUDP.SetSocketOption(SocketOptionLevel.Sock et,
SocketOptionName.Broadcast, 1);
m_SocketUDP.SetSocketOption(SocketOptionLevel.Sock et,
SocketOptionName.ReuseAddress, 1);

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


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;

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);
catch(Exception e)
WriteOutput("Error. "+ e.Message);

Anyone know whats wrong?

Dec 19 '05 #1
1 1922
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.


Mr. Jani Järvinen
Helsinki, Finland
Dec 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by pekspro | last post: by
2 posts views Thread by Jody L. Whitlock | last post: by
reply views Thread by Dave | last post: by
2 posts views Thread by Dave | last post: by
2 posts views Thread by ericlangland | last post: by
reply views Thread by leo001 | last post: by

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.