vb远程控制

vb远程控制,第1张

概述 远程控制服务端: Option ExplicitFunction WinSockInitial(ByVal WinSock As WinSock, ByVal IntPort As Long) As BooleanOn Error GoTo InitialError '验证winsock控件初始化连接的端口号) If 0 <= IntPort And Int

远程控制服务端:

Option ExplicitFunction WinSockInitial(ByVal WinSock As WinSock,ByVal IntPort As Long) As BooleanOn Error GoTo InitialError     '验证winsock控件初始化连接的端口号)    If 0 <= IntPort And IntPort <= 65535 Then        If IntPort Mod 1 = 0 Then            WinSock.LocalPort = IntPort            WinSockInitial = True            Exit Function        Else            MsgBox "端口配置应为整数",vbOKOnly + vbExclamation,"错误提示"            Exit Function        End If    ElseIf IntPort < 0 Then            MsgBox "端口配置为非负数","错误提示"            Exit Function    ElseIf IntPort > 65535 Then        MsgBox "端口配置超出最大值65535","错误提示"        Exit Function    End If    InitialError:    WinSockInitial = False    MsgBox "Unexpected error" & _            Str$(Err.Number) & _            " in subroutine WinSockInitial" & _            vbCrLf & _            Err.Description    Exit Function    End FunctionPrivate Sub Form_Load()'    '服务器端Winsock控件的初始化    If WinSockInitial(tcpserver,5000) = False Then        Unload Me        Exit Sub    Else        tcpserver.Listen        DeBUG.Print tcpserver.State        frmClIEnt.Show    End If    End SubPrivate Sub tcpserver_ConnectionRequest(ByVal requestID As Long)        '接受请求    If tcpserver.State <> sckClosed Then tcpserver.Close    tcpserver.Accept requestID    End SubPrivate Sub tcpserver_DataArrival(ByVal bytesTotal As Long)        Dim strData As String                       '声明一个变量,盛放数据    tcpserver.GetData strData,vbString         '调用GetData方法    txtOutPut.Text = txtOutPut.Text + strData   '将数据传送到txtOutPut文本框    End SubPrivate Sub txtSendData_KeyDown(KeyCode As Integer,Shift As Integer)    If KeyCode = vbKeyReturn Then        tcpserver.SendData txtSendData.Text    End IfEnd Sub


客户端:

Option ExplicitPrivate Sub Form_Load()    tcpClIEnt.RemoteHost = "192.168.24.156"    tcpClIEnt.RemotePort = 5000    tcpClIEnt.Connect                   '调用Connect方法初始化连接End Sub Private Sub Form_Unload(Cancel As Integer)    tcpClIEnt.Close         '关闭连接End SubPrivate Sub tcpClIEnt_DataArrival(ByVal bytesTotal As Long)    Dim strData As String               '声明变量盛放数据    If tcpClIEnt.State = 7 Then        tcpClIEnt.GetData strData           '调用GetData方法传送数据        txtOutPut.Text = strData            '将数据放到TxtOutPut文本框显示    End If    End SubPrivate Sub txtSend_KeyDown(KeyCode As Integer,Shift As Integer)        '按回车发送数据    If KeyCode = vbKeyReturn Then        tcpClIEnt.SendData txtSend.Text     '当文本框数据发生变换时,通过tcpClIEnt控件调用SendData方法发送数据    End If    End Sub

同时控制多台客户端的服务端:

Option ExplicitPrivate intMax As LongPrivate Sub Form_Load()    intMax = 0                      '初始化intMax变量    sckServer(0).LocalPort = 5000    sckServer(0).ListenEnd SubPrivate Sub sckServer_ConnectionRequest(Index As Integer,ByVal requestID As Long)    If Index = 0 Then        intMax = intMax + 1        Load sckServer(intMax)        sckServer(intMax).LocalPort = 0        sckServer(intMax).Accept requestID        Load txtData(intMax)    End IfEnd Sub
总结

以上是内存溢出为你收集整理的vb远程控制全部内容,希望文章能够帮你解决vb远程控制所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1290760.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存