3、P2P开发历程之——vb6之P2P简单实现(客户端)

这次发的是客户端

控件为包括5个textbox:text1 text2 text3 text4 text5

3个timer控件:timer1 timer2 timer3,

两个command按钮:command1 cmmand2,

两个winsock控件:WsktoServer WsktoClient

代码如下:

 

Dim temp As Integer

Private Sub Command1_Click()
    If Text1.Text <> "aaaa" And Text1.Text <> "bbbb" Then Exit Sub
    WsktoServer.Protocol = sckUDPProtocol
    WsktoServer.RemoteHost = "这里是你服务端的IP地址"
    WsktoServer.RemotePort = "服务端端口号"
    WsktoServer.Bind 2001
    
    WsktoServer.SendData "login|" & Text1.Text
    
    WsktoClient.Protocol = sckUDPProtocol
    WsktoClient.Bind 2002
    
End Sub

Private Sub Command2_Click()
 WsktoClient.SendData "msg|" & Text3.Text
End Sub

Private Sub Timer1_Timer()
    WsktoServer.SendData "beats"
End Sub

Private Sub Timer2_Timer()
    temp = temp + 1
    If temp > 10 Then
        Timer2.Interval = 0
        Text3.Text = "请测试发消息!"
        Command2.Enabled = True
        Timer3.Interval = 20000
    End If
    WsktoClient.SendData "beats"
End Sub

Private Sub Timer3_Timer()
    WsktoClient.SendData "beats"
End Sub

Private Sub WsktoServer_DataArrival(ByVal bytesTotal As Long)
        Dim tMsg As String
    Dim Cells() As String
    Dim tempIP As String
    Dim tempPort As String
    
    WsktoServer.GetData tMsg
    
    
    Cells = Split(tMsg, "|")
    
    Select Case Cells(0)
        Case "server"
            If Cells(1) = "ok" Then
                WsktoClient.RemoteHost = Cells(2)
                WsktoClient.RemotePort = Cells(3)
                Picture1.Visible = True
                Text4.Text = Cells(2)
                Text5.Text = Cells(3)
                Timer2.Interval = 500
            End If
        Case "msg"
            Text2.Text = Text2.Text + Cells(1) + vbCrLf
        End Select
            
    
End Sub

 

如果看不懂或懒得自己弄,去我刚发的资源里下载吧(嘿嘿,要10分,让你懒!)

http://download.csdn.net/detail/icbyboy/4890831

 


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杨正同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值