PDA

Click to See Complete Forum and Search --> : Socket / multicast... very interesting


manpowre
Jan 23rd, 2003, 01:46 PM
I'm having problems with the system.net.socket library.
I use 2 applications:
1. to multicast a file
2. to recieve the multicasted file

To multicast is NO problem.. I see the network card is very effective.

To recieve.. ARGHHHH I have checked most .NET forums, even C# to see if theres an answer to my problems with recieving the multicast.

Can you find an error in the recieve sub ?
The problem I get is that s.recieve hangs,,,it doesn't recieve anything..
UDPCLIENT class is BAD. It doesn't work with recieving at all.
Even MS has posted that recieving in UDPClient doesn't work...

So plzz I neeed some help here.


Sub subRecieve()
Dim varRecieveInterfaceMulticastIP As String = "228.64.0.210"
Dim varRecieveMcastIP As System.Net.IPAddress = System.Net.IPAddress.Parse(varRecieveInterfaceMulticastIP)
Dim RemoteIpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 11111)
Dim RemoteIpEndPoint2 As New System.Net.IPEndPoint(varRecieveMcastIP, 11111)
Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
s.Bind(RemoteIpEndPoint)
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, New MulticastOption(varRecieveMcastIP, System.Net.IPAddress.Any))
Do
Me.txtStatus.Text &= "R > "
Dim receiveBytes(900) As Byte
s.Receive(receiveBytes)
Loop
s.Close()
End Sub





Sub sendFile()
Do
Me.txtFilStatus.Text = "Starting to send file"
Dim varSendInterfaceMulticastIP As String = "228.64.0.210"
Dim varRecieveMcastIP As System.Net.IPAddress = System.Net.IPAddress.Parse(varSendInterfaceMulticastIP)
Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, New MulticastOption(varRecieveMcastIP))
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 2)
Dim RemoteIpEndPoint As New System.Net.IPEndPoint(varRecieveMcastIP, 11111)
s.Connect(RemoteIpEndPoint
Dim varBufferLen As Integer = 900
Dim fin As New FileStream("c:\testfile.dat", FileMode.Open, FileAccess.Read)
Dim bin(varBufferLen) As Byte
Dim rdlen As Long = 0
Dim len As Integer
Dim totlen As Long = fin.Length
While rdlen < totlen
len = fin.Read(bin, 0, varBufferLen)
If len = 0 Then Exit While
rdlen = Convert.ToInt32(rdlen + len)
Dim b() As Byte = bin
s.Send(b, b.Length, SocketFlags.None)
Me.txtFilStatus.Text = rdlen
End While
Me.txtFilStatus.Text = "Finished to send file"
Loop
End Sub

manpowre
Jan 24th, 2003, 01:26 AM
Anyone with good ideas ?