-
May 13th, 2010, 06:49 AM
#1
Not Receiving any data on udp port
Hi all,
I have a class UDPSocket inherited from .Net class 'UdpClient', Its code is as follows:
class UDPSocket : UdpClient
{
public UDPSocket()
{ }
public UDPSocket(int port)
{ }
public UDPSocket(IPEndPoint ep)
{ }
~UDPSocket()
{ }
}
There is also a CommunicationMgr class, which has the object of UDPSocket class, and is used for sending and receiving data from the socket. the code is given below:
public class CommunicationMgr
{
UDPSocket m_Socket;
IPAddress m_IPAddress;
public CommunicationMgr()
{
m_IPAddress = IPAddress.Parse("10.99.8.100");
m_Socket = new UDPSocket(1000);
}
~CommunicationMgr()
{ }
public void OnRequest()
{
IPEndPoint ipEndPoint = new IPEndPoint(m_IPAddress, 1000);
byte[] data = new byte[] { 0xbb, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xfb };
int datalength = data.Length;
int tt = m_Socket.Send(data, datalength, ipEndPoint);
}
public void OnResponse()
{
IPEndPoint remoteIpEndPoint = new IPEndPoint(ip, 1000);
byte[] receiveBytes = m_Socket.Receive(ref remoteIpEndPoint);
}
The application hangs at the receive function given below:
byte[] receiveBytes = m_Socket.Receive(ref remoteIpEndPoint);
Please note that if the same code is used with UdpClient class (ie, its object) instead of using object of the user-defined class UDPSocket then the application works!!!.
Can somebody please tell me what is wrong here??? Should i do anything in the UDPSocket's constructor?????
Regards
Daffodils180
-
March 18th, 2011, 01:12 AM
#2
Re: Not Receiving any data on udp port
you said program hangs while receive that may because at that data not avail and second option you may try with change IPEndPoint remoteIpEndPoint = new IPEndPoint(ip, 1000); to
IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
i am reading data on udp port using new IPEndPoint(IPAddress.Any, 0); you may also try..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|