📄 frmserver.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmserver
Caption = "tcp服务器"
ClientHeight = 5265
ClientLeft = 60
ClientTop = 345
ClientWidth = 6945
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5265
ScaleWidth = 6945
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtBack
Height = 2775
Left = 3720
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 7
Top = 1440
Width = 2895
End
Begin VB.CommandButton Command1
Caption = "读文件"
Height = 375
Left = 5400
TabIndex = 6
Top = 960
Width = 1335
End
Begin VB.CommandButton cmdSend
Caption = "发送"
Height = 375
Left = 5400
TabIndex = 5
Top = 360
Width = 1215
End
Begin VB.TextBox txtoutput
Height = 2775
Left = 360
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 1440
Width = 2655
End
Begin VB.TextBox txtsenddata
Height = 735
Left = 360
MultiLine = -1 'True
TabIndex = 0
Top = 360
Width = 4815
End
Begin MSWinsockLib.Winsock tcpserver
Left = 4440
Top = 0
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "输出"
Height = 180
Left = 360
TabIndex = 4
Top = 120
Width = 360
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "接收"
Height = 180
Left = 360
TabIndex = 3
Top = 1200
Width = 360
End
Begin VB.Label Label1
Height = 255
Left = 480
TabIndex = 2
Top = 4560
Width = 2895
End
End
Attribute VB_Name = "frmserver"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim TextLine As String
Dim conFlag As Boolean
Dim k As Integer
Private Sub cmdSend_Click()
'Dim strSend(1 To 6) As Byte
'strSend(1) = &H55
'strSend(2) = &H56
tcpserver.SendData (txtoutput.Text)
'tcpserver.SendData Right(strSend, 5)
End Sub
Private Sub Command1_Click()
'Dim TextLine
Open "asdf.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
'Debug.Print TextLine ' 在调试窗口中显示数据。
txtoutput.Text = TextLine
Loop
Close #1 ' 关闭文件。
End Sub
Private Sub Form_Load()
tcpserver.LocalPort = 10001
tcpserver.Listen
i = 0
End Sub
Private Sub tcpserver_Close()
tcpserver.Close
tcpserver.Listen
Label1.Caption = ""
End Sub
Private Sub tcpserver_ConnectionRequest(ByVal requestID As Long)
If tcpserver.State <> sckClosed Then
tcpserver.Close
End If
tcpserver.Accept requestID
Label1.Caption = CStr(tcpserver.RemoteHostIP)
End Sub
Private Sub tcpserver_DataArrival(ByVal bytesTotal As Long)
conFlag = True
'Dim strdata() As Byte
Dim receive_data(628) As Variant
Dim strdata As String
'Dim i, j As Integer
i = tcpserver.BytesReceived
'ReDim strdata(i)
tcpserver.GetData strdata, vbString, i
'txtoutput.Text = strdata
'tcpserver.GetData strdata, vbByte, i
' txtoutput.Text = Hex(strdata(0))
txtBack.Text = strdata
'For j = 0 To i - 1
'DoEvents
' txtBack.Text = txtBack.Text + Hex(strdata(j)) + " "
' Next
' If k = 1 Then Exit Sub
' tcpserver.SendData (TextLine)
' k = k + 1
' Open "back_file" For Append As #2 ' 打开文件。
' Print #2, txtBack.Text
' Close #2 ' 关闭文件。
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -