471,317 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

UDP Broadcast

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


Anyone know whats wrong?

Dec 20 '05 #1
0 1027

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Damir Hakimov | last post: by
6 posts views Thread by pekspro | last post: by
8 posts views Thread by Frank Esser | last post: by
2 posts views Thread by Shawn G. | last post: by
2 posts views Thread by Gunnar_Frenzel | last post: by
9 posts views Thread by Irmen de Jong | last post: by
2 posts views Thread by Mali Findik | last post: by
1 post views Thread by raviskar | last post: by
reply views Thread by rosydwin | 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.