By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Problem on MSDN

P: n/a
Hi Guys

I have just taken this article from msdn and it is coming up with an error
any ideas why? If any one wants to see where I found it
http://msdn.microsoft.com/library/de...dpservices.asp

There error i get is 'Sub Main' is declared more than once in
'ConsoleApplication2': ConsoleApplication2.UDPMulticastListener.Main(),
ConsoleApplication2.UDPMulticastListener.Main(args () As String) As Integer
[Visual Basic]
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class UDPMulticastListener

Private Shared GroupAddress As IPAddress = _
IPAddress.Parse("224.168.100.2")
Private Shared GroupPort As Integer = 11000

Private Shared Sub StartListener()
Dim done As Boolean = False

Dim listener As New UdpClient()
Dim groupEP As New IPEndPoint(GroupAddress, GroupPort)

Try
listener.JoinMulticastGroup(GroupAddress)
listener.Connect(groupEP)

While Not done
Console.WriteLine("Waiting for broadcast")
Dim bytes As Byte() = listener.Receive(groupEP)

Console.WriteLine("Received broadcast from {0} :" + _
ControlChars.Cr + " {1}" + ControlChars.Cr, _
groupEP.ToString(), _
Encoding.ASCII.GetString(bytes, 0, bytes.Length))
End While

listener.Close()

Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub 'StartListener

' Entry point that delegates to C-style main Private Function.
Public Overloads Shared Sub Main()
System.Environment.ExitCode = _
Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads Public Shared Function Main(args() As [String]) As Integer
StartListener()

Return 0
End Function 'Main
End Class 'UDPMulticastListener

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Michael Turner" <fi*****@m-turner.co.uk> schrieb:
I have just taken this article from msdn and it is coming up with an error
any ideas why? If any one wants to see where I found it
http://msdn.microsoft.com/library/de...dpservices.asp

There error i get is 'Sub Main' is declared more than once in
'ConsoleApplication2': ConsoleApplication2.UDPMulticastListener.Main(),
ConsoleApplication2.UDPMulticastListener.Main(args () As String) As Integer
[Visual Basic]
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class UDPMulticastListener

Private Shared GroupAddress As IPAddress = _
IPAddress.Parse("224.168.100.2")
Private Shared GroupPort As Integer = 11000

Private Shared Sub StartListener()
Dim done As Boolean = False

Dim listener As New UdpClient()
Dim groupEP As New IPEndPoint(GroupAddress, GroupPort)

Try
listener.JoinMulticastGroup(GroupAddress)
listener.Connect(groupEP)

While Not done
Console.WriteLine("Waiting for broadcast")
Dim bytes As Byte() = listener.Receive(groupEP)

Console.WriteLine("Received broadcast from {0} :" + _
ControlChars.Cr + " {1}" + ControlChars.Cr, _
groupEP.ToString(), _
Encoding.ASCII.GetString(bytes, 0, bytes.Length))
End While

listener.Close()

Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub 'StartListener
\\\
Public Shared Sub Main()
StartListener()
End Sub
///
End Class 'UDPMulticastListener


--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
Hi

Thanks, but I now get the following error

System.Net.Sockets.SocketException: An invalid argument was supplied
at System.Net.Sockets.Socket.setMulticastOption(Socke tOptionName
optionName,
MulticastOption MR)
at System.Net.Sockets.Socket.SetSocketOption(SocketOp tionLevel
optionLevel, S
ocketOptionName optionName, Object optionValue)
at System.Net.Sockets.UdpClient.JoinMulticastGroup(IP Address
multicastAddr)
at ConsoleApplication2.UDPMulticastListener.StartList ener() in
C:\Documents a
nd Settings\Michael\My Documents\Visual Studio
Projects\ConsoleApplication2\Modu
le1.vb:line 19

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...
"Michael Turner" <fi*****@m-turner.co.uk> schrieb:
I have just taken this article from msdn and it is coming up with an
error any ideas why? If any one wants to see where I found it
http://msdn.microsoft.com/library/de...dpservices.asp

There error i get is 'Sub Main' is declared more than once in
'ConsoleApplication2': ConsoleApplication2.UDPMulticastListener.Main(),
ConsoleApplication2.UDPMulticastListener.Main(args () As String) As
Integer
[Visual Basic]
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class UDPMulticastListener

Private Shared GroupAddress As IPAddress = _
IPAddress.Parse("224.168.100.2")
Private Shared GroupPort As Integer = 11000

Private Shared Sub StartListener()
Dim done As Boolean = False

Dim listener As New UdpClient()
Dim groupEP As New IPEndPoint(GroupAddress, GroupPort)

Try
listener.JoinMulticastGroup(GroupAddress)
listener.Connect(groupEP)

While Not done
Console.WriteLine("Waiting for broadcast")
Dim bytes As Byte() = listener.Receive(groupEP)

Console.WriteLine("Received broadcast from {0} :" + _
ControlChars.Cr + " {1}" + ControlChars.Cr, _
groupEP.ToString(), _
Encoding.ASCII.GetString(bytes, 0, bytes.Length))
End While

listener.Close()

Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub 'StartListener

\\\
Public Shared Sub Main()
StartListener()
End Sub
///
End Class 'UDPMulticastListener


--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.