我与VB之Winsock篇(一)
作者:枫雪 文章来源:原创 更新时间:2008-3-23
越来越觉得自己不是搞技术的料了,搞点小东西都觉得力不从心啊!说到这,真的很佩服电脑圈圈和匠人,05年跟圈圈吃过饭,那时正要毕业,是去他那边寻求帮助的。虽然没见过匠人,但看他的博客,不得不佩服啊!尽力搞的,反正也不是工作,只是业余的,能学好就开心了,压力没那么大!
今晚从8点搞到现在,从写了一个最简单的软件,简单到自己都不好意思,不管怎样,起码成功了第一步
这是VB写的界面,够简单吧
这个是51TCP板发数据给VB接收后的图,TCP板发送字符16000
下面是VB代码,先发上来,以后还要接着改,习惯不好,都没写些注释,呵呵,大家见谅!
Dim Num As Integer
Dim locPort As Integer
Dim color(2) As Long
Dim cur As Integer
Public tmin As Integer
Public tmax As Integer
Public repet As Integer
Dim remain As Integer
Dim SoundFile As String
Dim Result As Long
Private Sub Form_Load()
Num = 50
locPort = 2000
tmin = 12
tmax = 26
repet = 5
Call init
End Sub
Sub init()
remain = 0
color(0) = &HFF00& '&H0000FF00&
color(1) = &HFF& '&H000000FF&
color(2) = &HFFFF& '&H0000FFFF&
sock(0).LocalPort = locPort
sock(0).Listen
For i = 1 To Num
Load sock(i)
sock(i).LocalPort = locPort + i
sock(i).Listen
Next
Label2.Caption = "本地IP: " & sock(0).LocalIP
Label3.Caption = "信息: 已连接" & cur & "/" & Num
End Sub
Private Sub sock_Close(Index As Integer)
sock(Index).Close
sock(Index).Listen
Shape1.FillColor = color(2)
cur = cur - 1
Labtem1 = ""
End Sub
Private Sub sock_ConnectionRequest(Index As Integer, ByVal requestID As Long)
sock(Index).Close
sock(Index).Accept requestID
cur = cur + 1
Label3.Caption = "信息: 已连接" & cur & "/" & Num
End Sub
Private Sub sock_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim s As String
sock(Index).GetData s ' DataFormat XX0YYY
Call reflec(s)
End Sub
Sub reflec(data As String)
Labtem1.Caption = data
End Sub
文章评论(0条评论)
登录后参与讨论