943,620 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3251
  • C# RSS
Mar 9th, 2009
0

UDP problem with C++ sendto() --> C# ReceiveFrom()

Expand Post »
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#:
C# Syntax (Toggle Plain Text)
  1. m_listenEp = new IPEndPoint(IPAddress.Any, m_Udplisten_port);
  2. m_UdpListenSocket = new Socket(m_listenEp.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
  3. m_UdpListenSocket.Bind(m_listenEp);
  4.  
  5. m_sendEp = new System.Net.IPEndPoint(addr, m_Udpsend_port);
  6. m_UdpSendSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  7.  
  8. m_UdpSendSocket.SendTo(msgBuffer, msgBuffer.Length, SocketFlags.None, m_sendEp);

C++:
C++ Syntax (Toggle Plain Text)
  1. SOCKET m_sfd;
  2. recvfrom(m_sfd,buf,maxLen,0,(struct sockaddr *)src, &fromlen);
  3. sendto(m_sfd,buf,len,0,(struct sockaddr *)src,
  4. sizeof(struct sockaddr_in));

Thanks in advance.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
VRspace4 is offline Offline
1 posts
since Mar 2009
Mar 10th, 2009
0

Re: UDP problem with C++ sendto() --> C# ReceiveFrom()

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?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: adding items in Combobox runtime in datagridview
Next Thread in C# Forum Timeline: Combo box trouble





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC