Hello,

I'm writing a simple C# connectionless UDP application that communicates with a C++ connectionless UDP app. I could send from the C# to C++ using the following sets of functions fine:

Send from C# to C++
C#: SendTo()
C++: recvfrom()

However, I'm having trouble receiving the C++ UDP messages from the C# application. The recvfrom() from the C++ app appears to be generating random source information, which is then used as the destination for the sendto() C++ function.

The limitation is that I can only make changes to the C# application and not the C++'s. Below is how I implemented the UDP for both C# and C++ app.

C#:

m_listenEp = new IPEndPoint(IPAddress.Any, m_Udplisten_port);
m_UdpListenSocket = new Socket(m_listenEp.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
m_UdpListenSocket.Bind(m_listenEp);

m_sendEp = new System.Net.IPEndPoint(addr, m_Udpsend_port);
m_UdpSendSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

m_UdpSendSocket.SendTo(msgBuffer, msgBuffer.Length, SocketFlags.None, m_sendEp);

C++:

SOCKET      m_sfd;
recvfrom(m_sfd,buf,maxLen,0,(struct sockaddr *)src, &fromlen);
sendto(m_sfd,buf,len,0,(struct sockaddr *)src,
            sizeof(struct sockaddr_in));

Thanks in advance.

UDP stuff is always harder to work with as you cant guarentee its arrival. Have you tried a packet sniffer on the recieving end to ensure its getting there?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.