I have a question regarding code examples in the msdn cd.
For example I will refer to the help page titled
"Using TCP Services"
As we can see, the code below is supposed to be for
a console application. My question is this: if I create
a console application with the wizard, I get a Main
sub which is inside Module1, whereas here, in the
sample, main is in a class called TcpTimeClient.
I.e. there is some implicit understanding here that one
would know how to insert this sample into the basic
template that the Console Application wizard gives
us. Is this mentioned anywhere ?
[Visual Basic]
Imports System
Imports System.Net.Sock ets
Imports System.Text
Public Class TcpTimeClient
Private const portNum As Integer = 13
Private const hostName As String = "host.contoso.c om"
' Entry point that delegates to C-style main Private Function.
Public Overloads Shared Sub Main()
System.Environm ent.ExitCode = _
Main(System.Env ironment.GetCom mandLineArgs())
End Sub
Overloads Public Shared Function Main(args() As [String]) As Integer
Try
Dim client As New TcpClient(hostN ame, portNum)
Dim ns As NetworkStream = client.GetStrea m()
Dim bytes(1024) As Byte
Dim bytesRead As Integer = ns.Read(bytes, 0, bytes.Length)
Console.WriteLi ne(Encoding.ASC II.GetString(by tes, 0, bytesRead))
Catch e As Exception
Console.WriteLi ne(e.ToString() )
End Try
client.Close()
Return 0
End Function 'Main
End Class 'TcpTimeClient
For example I will refer to the help page titled
"Using TCP Services"
As we can see, the code below is supposed to be for
a console application. My question is this: if I create
a console application with the wizard, I get a Main
sub which is inside Module1, whereas here, in the
sample, main is in a class called TcpTimeClient.
I.e. there is some implicit understanding here that one
would know how to insert this sample into the basic
template that the Console Application wizard gives
us. Is this mentioned anywhere ?
[Visual Basic]
Imports System
Imports System.Net.Sock ets
Imports System.Text
Public Class TcpTimeClient
Private const portNum As Integer = 13
Private const hostName As String = "host.contoso.c om"
' Entry point that delegates to C-style main Private Function.
Public Overloads Shared Sub Main()
System.Environm ent.ExitCode = _
Main(System.Env ironment.GetCom mandLineArgs())
End Sub
Overloads Public Shared Function Main(args() As [String]) As Integer
Try
Dim client As New TcpClient(hostN ame, portNum)
Dim ns As NetworkStream = client.GetStrea m()
Dim bytes(1024) As Byte
Dim bytesRead As Integer = ns.Read(bytes, 0, bytes.Length)
Console.WriteLi ne(Encoding.ASC II.GetString(by tes, 0, bytesRead))
Catch e As Exception
Console.WriteLi ne(e.ToString() )
End Try
client.Close()
Return 0
End Function 'Main
End Class 'TcpTimeClient