日期:2012-08-27  浏览次数:20578 次

Option Explicit On
Option Strict On

Imports System
Imports System.IO
Imports System.Text
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.VisualBasic



Class App
    
    'Entry point which delegates to C-style main Private Function
    Public Overloads Shared Sub Main()
        Main(System.Environment.GetCommandLineArgs())
    End Sub
    
    ' Entry point
    Overloads Public Shared Sub Main(args() As String)
        ' If the args parse in known way then run the app
        If ParseArgs(args) Then
            ' Create a custom Talker object
            Dim talkerObj As New Talker(endPoint, client)
            ' Pass the object reference to a new form object
            Dim form As New TalkForm(talkerObj)
            ' Start the talker "talking"
            talkerObj.Start()
            
            ' Run the applications message pump
            Application.Run(form)
        End If
    End Sub 'Main
    
    ' Parsed Argument Storage
    Private Shared endPoint As IPEndPoint
    Private Shared client As Boolean
    
    
    ' Parse command line arguments
    Private Shared Function ParseArgs(args() As String) As Boolean
        Try
            If args.Length = 1 Then
                client = False
                endPoint = New IPEndPoint(IPAddress.Any, 5150)
                Return True
            End If
           
            Dim port As Integer
            Select Case Char.ToUpper(args(1).ToCharArray()(1))
                Case "L"c
                    port = 5150
                    If args.Length > 2 Then
                        port = Convert.ToInt32(args(2))