?? frmoutclientserver.frm
字號:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmOutClientServer
Caption = "外網(wǎng)客戶接收攜帶新地址端口的數(shù)據(jù)包"
ClientHeight = 6045
ClientLeft = 60
ClientTop = 450
ClientWidth = 7320
LinkTopic = "Form1"
ScaleHeight = 6045
ScaleWidth = 7320
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdConnect
Caption = "開始連接新端口"
Height = 375
Left = 3735
TabIndex = 26
Top = 3165
Width = 1560
End
Begin VB.CommandButton cmdCall
Caption = "用新端口發(fā)數(shù)據(jù)"
Height = 375
Left = 5475
TabIndex = 25
Top = 3165
Width = 1560
End
Begin VB.CommandButton cmdOk
Caption = "開始監(jiān)聽端口"
Height = 375
Left = 360
TabIndex = 12
Top = 3180
Width = 1560
End
Begin VB.TextBox txtService
Height = 285
Index = 6
Left = 5400
TabIndex = 11
Text = "Text1"
Top = 1260
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 5
Left = 5400
TabIndex = 10
Text = "Text1"
Top = 870
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 4
Left = 1935
TabIndex = 9
Text = "Text1"
Top = 2055
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 3
Left = 1950
TabIndex = 8
Text = "Text1"
Top = 1680
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 2
Left = 1935
TabIndex = 7
Text = "Text1"
Top = 1260
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 1
Left = 1950
TabIndex = 6
Text = "Text1"
Top = 855
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 7
Left = 5400
TabIndex = 5
Text = "Text1"
Top = 1650
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 8
Left = 5400
TabIndex = 4
Text = "Text1"
Top = 2055
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 0
Left = 1950
TabIndex = 0
Text = "Text1"
Top = 495
Width = 5025
End
Begin VB.TextBox txtService
Height = 285
Index = 9
Left = 1950
TabIndex = 3
Text = "Text1"
Top = 2685
Width = 1575
End
Begin VB.TextBox txtService
Height = 285
Index = 10
Left = 5385
TabIndex = 2
Text = "Text1"
Top = 2670
Width = 1575
End
Begin VB.TextBox txtDisplay
Height = 2235
Left = 345
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 1
Text = "frmOutClientServer.frx":0000
Top = 3720
Width = 6660
End
Begin MSWinsockLib.Winsock wskOut
Left = 2340
Top = 3180
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "請輸入以下字段:"
Height = 195
Left = 330
TabIndex = 24
Top = 225
Width = 1440
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "內(nèi)網(wǎng)客戶初始端口:"
Height = 195
Index = 2
Left = 330
TabIndex = 23
Top = 1305
Width = 1620
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "內(nèi)網(wǎng)客戶新端口:"
Height = 195
Index = 4
Left = 330
TabIndex = 22
Top = 2130
Width = 1440
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "內(nèi)網(wǎng)客戶新地址:"
Height = 195
Index = 3
Left = 330
TabIndex = 21
Top = 1725
Width = 1440
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "內(nèi)網(wǎng)客戶初始地址:"
Height = 195
Index = 1
Left = 330
TabIndex = 20
Top = 900
Width = 1620
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "NAT外網(wǎng)初始端口:"
Height = 195
Index = 6
Left = 3690
TabIndex = 19
Top = 1305
Width = 1590
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "NAT外網(wǎng)新端口:"
Height = 195
Index = 8
Left = 3690
TabIndex = 18
Top = 2115
Width = 1410
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "NAT外網(wǎng)新地址:"
Height = 195
Index = 7
Left = 3690
TabIndex = 17
Top = 1725
Width = 1410
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "NAT外網(wǎng)初始地址:"
Height = 195
Index = 5
Left = 3690
TabIndex = 16
Top = 900
Width = 1590
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "所用協(xié)議:"
Height = 195
Index = 0
Left = 330
TabIndex = 15
Top = 540
Width = 900
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "外網(wǎng)客戶端口:"
Height = 195
Index = 10
Left = 3690
TabIndex = 14
Top = 2715
Width = 1260
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "外網(wǎng)客戶地址:"
Height = 195
Index = 9
Left = 315
TabIndex = 13
Top = 2700
Width = 1260
End
Begin VB.Line Line1
Index = 0
X1 = 345
X2 = 7065
Y1 = 2535
Y2 = 2535
End
Begin VB.Line Line1
BorderColor = &H80000004&
Index = 1
X1 = 345
X2 = 7050
Y1 = 2550
Y2 = 2550
End
Begin VB.Line Line1
Index = 2
X1 = 345
X2 = 7065
Y1 = 3045
Y2 = 3045
End
Begin VB.Line Line1
BorderColor = &H80000004&
Index = 3
X1 = 345
X2 = 7050
Y1 = 3060
Y2 = 3060
End
End
Attribute VB_Name = "frmOutClientServer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private cbdFromInClient As clsBringData '數(shù)據(jù)包對象
'0.初始化文本框數(shù)據(jù)
Private Sub Form_Load()
txtService(0).Text = "TCP"
txtService(1).Text = ""
txtService(2).Text = ""
txtService(3).Text = ""
txtService(4).Text = ""
txtService(5).Text = ""
txtService(6).Text = ""
txtService(7).Text = ""
txtService(8).Text = ""
txtService(9).Text = "193.168.22.44"
txtService(10).Text = 991
txtDisplay.Text = ""
End Sub
'1.開始監(jiān)聽端口,以接收來自內(nèi)網(wǎng)客戶端的連接請求
Private Sub cmdOk_Click()
DisplayMsg "開始監(jiān)聽端口:" & txtService(10).Text
wskOut.LocalPort = txtService(10).Text
wskOut.Listen
End Sub
'1.接收來自內(nèi)網(wǎng)客戶端的連接請求
Private Sub wskOut_ConnectionRequest(ByVal requestID As Long)
'檢查控件的 State 屬性是否為關(guān)閉的。
'如果不是,
'在接受新的連接之前先關(guān)閉此連接。
If wskOut.State <> sckClosed Then wskOut.Close
'接受具有 requestID 參數(shù)的連接。
wskOut.Accept requestID
DisplayMsg "接收來自內(nèi)網(wǎng)客戶端的連接"
End Sub
'1.連接完成后,接收來自內(nèi)網(wǎng)客戶端的數(shù)據(jù)包
Private Sub wskOut_DataArrival(ByVal bytesTotal As Long)
Dim strTemp As String
wskOut.GetData strTemp
Set cbdFromInClient = New clsBringData
cbdFromInClient.StringToDataField strTemp
DisplayMsg "獲得來自內(nèi)網(wǎng)客戶端的數(shù)據(jù)"
DisplayMsg "數(shù)據(jù)內(nèi)容為:" & cbdFromInClient.strDisplay
FillData
txtService(5).Text = wskOut.RemoteHostIP
txtService(6).Text = wskOut.RemotePort
End Sub
'2.換內(nèi)網(wǎng)客戶端為服務(wù)器。連接到內(nèi)網(wǎng)客戶端,實(shí)際上是連接到NAT
Private Sub cmdConnect_Click()
DisplayMsg "連接內(nèi)網(wǎng)客戶端..."
wskOut.Close
If txtService(0).Text = "TCP" Then
wskOut.Protocol = sckTCPProtocol
Else
wskOut.Protocol = sckUDPProtocol
End If
wskOut.Connect txtService(7).Text, txtService(8).Text
End Sub
'2.如果連接到內(nèi)網(wǎng)客戶端則顯示相關(guān)信息
Private Sub wskOut_Connect()
DisplayMsg "完成連接內(nèi)網(wǎng)客戶端..."
End Sub
'2.連接到內(nèi)網(wǎng)客戶端后,發(fā)送數(shù)據(jù)包
Private Sub cmdCall_Click()
DisplayMsg "開始用新地址端口發(fā)送數(shù)據(jù)..."
DisplayMsg "開始生成數(shù)據(jù)包..."
cbdFromInClient.strDisplay = "來自" & wskOut.LocalIP & ":" & wskOut.LocalPort & "的數(shù)據(jù)包。使用新地址端口發(fā)送。"
cbdFromInClient.strOldNatIP = txtService(5).Text
cbdFromInClient.strOldNatPort = txtService(6).Text
DisplayMsg "完成數(shù)據(jù)包"
DisplayMsg "發(fā)送數(shù)據(jù)包到內(nèi)網(wǎng)客戶端..."
wskOut.SendData cbdFromInClient.DataFieldToString
DisplayMsg "完成發(fā)送數(shù)據(jù)包到內(nèi)網(wǎng)客戶端"
End Sub
'根據(jù)數(shù)據(jù)包填充文本框
Private Sub FillData()
txtService(1).Text = cbdFromInClient.strOldIP
txtService(2).Text = cbdFromInClient.strOldPort
txtService(3).Text = cbdFromInClient.strNewIP
txtService(4).Text = cbdFromInClient.strNewPort
txtService(5).Text = cbdFromInClient.strOldNatIP
txtService(6).Text = cbdFromInClient.strOldNatPort
txtService(7).Text = cbdFromInClient.strNewNatIP
txtService(8).Text = cbdFromInClient.strNewNatPort
End Sub
'改變文本框的底色
Private Sub txtService_GotFocus(Index As Integer)
txtService(Index).BackColor = &H80000018
End Sub
'改變文本框的底色
Private Sub txtService_LostFocus(Index As Integer)
txtService(Index).BackColor = vbWhite
End Sub
'處理文本框中按下回車鍵
Private Sub txtService_KeyPress(Index As Integer, KeyAscii As Integer)
Dim intTemp As Integer
If KeyAscii = 13 Then
If Index = txtService.UBound Then
intTemp = txtService.LBound
Else
intTemp = Index + 1
End If
txtService(intTemp).SetFocus
KeyAscii = 0
End If
End Sub
'顯示信息
Private Sub DisplayMsg(strMsg As String)
txtDisplay.Text = txtDisplay.Text & DateTime.Now & " --> " & strMsg & Chr(13) & Chr(10)
txtDisplay.SelStart = Len(txtDisplay.Text)
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -