Udp multicast receive problem c#

G

Guest

i am writing an ActiveX control in c# that connects to a multicast. It works properly the problem is that when i run my webapp that contains the ActiveX control, then the broadcast is sent i do not receive the datagram for a minute and fourty five seconds. I need to be able to receive that datagram immediately.

I tried to change the size of the receive buffer to a smaller value, byte[] MessageBuffer = new Byte[10000
I immediately receive an error, A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram was smaller than the datagram itself. When i make this buffer larger, byte[] MessageBuffer = new Byte[25000] i do not receive the error immediately, and i am stuck waiting to receive the data.

An important note about this problem is that once data has been received for the first time, i can run the multicast sender and i can receive just fine. it is just the problem of getting past that first hump. Any help would be greatly appreciated

this is called in this
_receiveSocket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp)

IPEndPoint ipept = new IPEndPoint(IPAddress.Any, _multiCastPort)

_receiveSocket.Bind(ipept)

IPAddress ip = IPAddress.Parse(_multiCastIP)

_receiveSocket.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.AddMembership,new MulticastOption(ip))

byte[] MessageBuffer = new byte[25000]

_receiveSocket.ReceiveFrom(MessageBuffer,0,25000,SocketFlags.None,ref ep)

i have also tried to use a ucpclient for this and i still get the same problem.
 
G

Guest

after further examination of the problem. I have found that when the multicast is sent the receiving socket automatically receives the datagram, the problem is that 3 new tcp process are created

iexplore.exe:process# tcp 0.0.0.0:2961 0.0.0.0:0 listenin
inetinfo.exe:inetinfoprocess# tcp 127.0.0.1:80 127.0.0.1:2961 establishe
iexplore.exe:process# tcp 127.0.0.1:2961 127.0.0.1:80 establishe

until these close out after a minute and forty seconds everytime, i dont 'receive' the packet. any time after that i receive immediately. I believe this has something to do with the fact that the listener is run in a Com objectand that i may have declared it incorrectly.
 
S

Stephan Steiner

I've been working with UDP sockets a long while back but I recall having
problems receiving the first packets.

I ended up with the following workaround:
When setting up the receiving socket, I sent a 2 byte datagram to myself,
and tried to receive from the socket to clear the buffer once again. After
doing that, reception no longer was a problem and when the sender started
sending, the receiver started receiving right away.

Also, be careful about socket buffers.. they not always work as advertised.
For instance, you can set the buffer to zero bytes, which should result in
you not being able to receive anything. But, try it, send a large amount of
data, then call a Socket.Receive on the receiver socket.. you'll end up with
datagrams even though you should not (but not many.. decreasing the buffer
does have some effect but it doesn't go all the way).

Anyway, I hope that helps.

Regards
Stephan


mjcast said:
after further examination of the problem. I have found that when the
multicast is sent the receiving socket automatically receives the datagram,
the problem is that 3 new tcp process are created;
iexplore.exe:process# tcp 0.0.0.0:2961 0.0.0.0:0 listening
inetinfo.exe:inetinfoprocess# tcp 127.0.0.1:80 127.0.0.1:2961 established
iexplore.exe:process# tcp 127.0.0.1:2961 127.0.0.1:80 established

until these close out after a minute and forty seconds everytime, i dont
'receive' the packet. any time after that i receive immediately. I believe
this has something to do with the fact that the listener is run in a Com
objectand that i may have declared it incorrectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top