CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Location
    .NET 3.5, VisualStudio-2008
    Posts
    30

    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

  2. #2
    Join Date
    Mar 2011
    Posts
    1

    Post 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
  •  





Click Here to Expand Forum to Full Width

Featured