作者:枫雪 文章来源:原创 更新时间:2008-3-24
接着昨晚的脚步,今晚要搞的是电脑发数据给TCP板,而TCP返回指定的数据,毕竟是通信嘛,单向就没多大用处,收不到时想让发送方再发一次都不行,可靠性不高!现在是熟悉控件,等熟悉了控件,再写一个完善版!现在的软件不都是分1.0版,1.1版什么的,也要学学人家嘛!偷偷地说,主要是本人笨,不能一下子写个比较好的程序,只能一步步,用最笨的方法了!好了,上图,也是最简单的,希望大家喜欢
第一个,是没连接上TCP板的图
第二个,是连接上TCP板的图,显示“HELLO TCP”字符来做提示
第三个,是往TCP板发数据,TCP板返回预设“160”
最后是代码
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 Command1_Click()
sock(0).SendData Text1.Text
End Sub
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
用户71098 2008-3-25 13:43
用户118339 2008-3-25 11:47
用户51198 2008-3-25 09:24