文件名称:
使用vbRichClient代替winsock,实现局网多客户端非gui数据收发
开发工具:
文件大小: 3kb
下载次数: 0
上传时间: 2016-01-14
详细说明: 发现网上关于vbrichclient的教程比较少,但这个实在是好东西,实用性,稳定性都比VB自带的winsock好的多,多客户端不用winsock控件数组。 也不用在各窗体上放winsock,直接在模块中就能实现收发 下面直接上代码,窗体和文本钮、按钮大家自行拖放。要用到VB自带隐藏函数varptr()取内存指针(VbMsdn中没有这个函数,实际上很简单^^)。 VbRichClient5.0.38中包含sqlite3.9支持 上面共享中也包含VbRichClient5.0.38支持库 VbRichClient代替winsock 主要使用 cTCPServer cTCPClient cUDP '--------------------------------------------------------------------- '服务器端,代码最简化,要实现多客户端只要用数组存hsocket就可以 Option Explicit Dim WithEvents sv As cTCPServer Dim WithEvents udp1 As cUDP Dim cHsocket& Private Sub Form_Load() Se t sv = New cTCPServer sv.Listen sv.GetHost("127.0.0.1"), 35912 Debug.Print sv.GetHost("") Set udp1 = New cUDP udp1.Bind "127.0.0.1", 5616 End Sub Private Sub sv_DataArrival(ByVal hSocket As Long, ByVal BytesTotal As Long, ByVal FirstBufferAfterOverflow As Boolean) Dim d() As Byte, s$ ReDim d(BytesTotal - 1) sv.GetData hSocket, VarPtr(d(0)), BytesTotal '★★关键代码 s = d Text2.Text = Text2.Text & s & vbCrLf Debug.Print "收到:" & BytesTotal End Sub Private Sub sv_TCPAccepted(ByVal hSocket As Long) cHsocket = hSocket Text1.Text = Text1.Text & sv.GetPeerHostIPAndPort(hSocket) & vbCrLf End Sub Private Sub sv_TCPDisConnect(ByVal hSocket As Long) Text3.Text = Text3.Text & sv.GetPeerHostIPAndPort(hSocket) & vbCrLf End Sub Private Sub udp1_NewDatagram(ByVal BytesTotal As Long, ByVal FirstBufferAfterOverflow As Boolean) Dim d() As Byte, s$ ReDim d(BytesTotal - 1) udp1.GetData VarPtr(d(0)), BytesTotal s = d Text2.Text = Text2.Text & s & vbCrLf End Sub '------------------------------------------------------- '客户端 Option Explicit Dim WithEvents cl As cTCPClient Dim WithEvents udp1 As cUDP Dim cid& Private Sub Command1_Click() cid = cl.Connect("QgB1", 35912) End Sub Private Sub Command2_Click() cl.Disconnect cid End Sub Private Sub Command3_Click() Dim b() As Byte b = Text1.Text cl.SendData cid, VarPtr(b(0)), UBound(b) + 1 End Sub Private Sub Command4_Click() Dim d() As Byte, s$ s = "yessss" d = s udp1.RemoteIP = "127.0.0.1" udp1.RemotePort = 5616 udp1.SendData VarPtr(d(0)), UBound(d) + 1 '★★关键代码 End Sub Private Sub Form_Load() Set cl = New cTCPClient Set udp1 = New cUDP udp1.Bind "127.0.0.1", 3941 End Sub Private Sub udp1_NewDatagram(ByVal BytesTotal As Long, ByVal FirstBufferAfterOverflow As Boolean) Dim d() As Byte ReDim d(BytesTotal - 1) Text2.Text = udp1.GetData(VarPtr(d(0)), BytesTotal) '★★关键代码 End Sub ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.