📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'连接服务器名称和端口,根据每台计算机而不同
AxWinsock1.Protocol = MSWinsockLib.ProtocolConstants.sckUDPProtocol
AxWinsock1.RemoteHost = "127.0.0.1"
AxWinsock1.RemotePort = 2200
AxWinsock1.LocalPort = 1100
AxWinsock1.Bind()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents AxWinsock1 As AxMSWinsockLib.AxWinsock
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
'Required by the Windows Form Designer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private components As System.ComponentModel.IContainer
Friend WithEvents textbox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.textbox1 = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.AxWinsock1 = New AxMSWinsockLib.AxWinsock()
Me.Button2 = New System.Windows.Forms.Button()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
CType(Me.AxWinsock1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'textbox1
'
Me.textbox1.Location = New System.Drawing.Point(8, 144)
Me.textbox1.Multiline = True
Me.textbox1.Name = "textbox1"
Me.textbox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.textbox1.Size = New System.Drawing.Size(328, 104)
Me.textbox1.TabIndex = 3
Me.textbox1.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(120, 128)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 1
Me.Label1.Text = "接收到的信息"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(128, 8)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 2
Me.Label2.Text = "要发送的信息"
'
'AxWinsock1
'
Me.AxWinsock1.Enabled = True
Me.AxWinsock1.Location = New System.Drawing.Point(40, 272)
Me.AxWinsock1.Name = "AxWinsock1"
Me.AxWinsock1.OcxState = CType(resources.GetObject("AxWinsock1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxWinsock1.Size = New System.Drawing.Size(28, 28)
Me.AxWinsock1.TabIndex = 0
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(200, 256)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 6
Me.Button2.Text = "退出"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(8, 32)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox2.Size = New System.Drawing.Size(328, 88)
Me.TextBox2.TabIndex = 4
Me.TextBox2.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(72, 256)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 5
Me.Button1.Text = "发送"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(352, 285)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1, Me.TextBox2, Me.textbox1, Me.Label2, Me.Label1, Me.AxWinsock1})
Me.Name = "Form1"
Me.Text = "服务器"
CType(Me.AxWinsock1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' MessageBox.Show(TextBox2.Text)
AxWinsock1.SendData(TextBox2.Text)
End Sub
'退出程序
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
'数据到达时
Private Sub AxWinsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles AxWinsock1.DataArrival
Dim strData As Object
Dim i As Integer
Dim tString As String
'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -