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

来源:互联网 发布:泰国棒糖妹网络直播 编辑:程序博客网 时间:2024/05/22 14:44

这次发的是客户端

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

3个timer控件:timer1 timer2 timer3,

两个command按钮:command1 cmmand2,

两个winsock控件:WsktoServer WsktoClient

代码如下:

 

Dim temp As IntegerPrivate 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 SubPrivate Sub Command2_Click() WsktoClient.SendData "msg|" & Text3.TextEnd SubPrivate Sub Timer1_Timer()    WsktoServer.SendData "beats"End SubPrivate 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 SubPrivate Sub Timer3_Timer()    WsktoClient.SendData "beats"End SubPrivate 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