talkerservice.vb
来自「Visual Basic.NET控件时尚编程百例」· VB 代码 · 共 70 行
VB
70 行
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threading
Imports System.Net.Sockets
Imports System.Windows.Forms
Class TalkerService
Public Shared endPoint As IPEndPoint
Public Shared client As Boolean
Public Shared Sub Main(ByVal args() As String)
'如果命令行参数符合要求,则运行该程序
If ParseArgs(args) Then
Dim talkerObj As New Talker(endPoint, client)
'实例化Talker类
Dim form As New frmTalker(talkerObj)
'实例化TalkForm类,并传递Talker对象
talkerObj.Start()
'启动对象
Application.Run(form)
'运行程序
End If
End Sub
Private Shared Function ParseArgs _
(ByVal args() As String) As Boolean
'分析命令行参数
Try
If args.Length = 0 Then
client = False
endPoint = New IPEndPoint(IPAddress.Any, 5150) '
' 获取IP地址
Return True
End If
If Not (args(0).ToCharArray()(0) = "/" Or _
args(0).ToCharArray()(0) = "-") Then
Return False
End If
Dim port As Integer
Select Case Char.ToUpper(args(0).ToCharArray()(1))
Case "L"c
port = 5150
If args.Length > 1 Then
port = Convert.ToInt32(args(1))
End If
endPoint = New IPEndPoint(IPAddress.Any, port)
client = False
Case "C"c
port = 5150
Dim address As String = "127.0.0.1"
client = True
If args.Length > 1 Then
address = args(1)
port = Convert.ToInt32(args(2))
End If
endPoint = New IPEndPoint _
(Dns.Resolve(address).AddressList(0), port)
Case Else
Return False
End Select
Catch
End Try
Return True
End Function
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?