vbcaiquan

Dim imgPath        As String
Dim choosedImgPath As String
Dim choosed        As String
Dim myName         As String
Dim ipaddress      As String '桭払偺IP :
Dim canImgCli      As Boolean
Dim game123        As Integer '僎乕儉忬懺


Private Sub Form_Load()
    pageInit
    
    Dim ipname As String
    Dim Bind() As String

    '埲ip抧毈揑嵟屻堦慻壛忋1000嶌堊杮抧揑抂岥
    ipname = Winsock.LocalIP
    'ip傾僪儗僗傪暘妱偡傞
    Bind = Split(ipname, ".")
    '埲洈曽揑IP抧毈嵟屻堦慻壛忋1000嶌堊懳曽揑抂岥
    Winsock.Bind (1000 + Bind(3))
    'txtOutput擖椡偱偒側偄
    txtOutPut.Locked = True
    cmdConnect.Enabled = False
    
    cmdSend.Enabled = False
    cmdSelMsg.Enabled = False
    txtMsg.Enabled = False
    cmdSure.Enabled = False
    
    canImgCli = True
    game123 = 0


End Sub



Private Sub cobFriendIp_Change()
    cmdConnect.Enabled = False
    '敾抐惀IP斲惓?
    ipaddress = cobFriendIp.Text
    
    If isValidIpAddress(ipaddress) Then
    
        cmdConnect.Enabled = True
        
    End If
End Sub

'IP偑惓偟偄偐偳偆偐傪敾抐偡傞
Private Function isValidIpAddress(strIpAddress As String) As Boolean
    Dim reg As New RegExp, i As Integer
    Dim strArr() As String
    reg.IgnoreCase = True
    reg.Global = True
    reg.MultiLine = True
    reg.Pattern = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"
 
    isValidIpAddress = reg.Test(strIpAddress)
 
    If isValidIpAddress = True Then
        
        strArr = Split(strIpAddress, ".")
 
        For i = 0 To UBound(strArr)
            isValidIpAddress = isValidIpAddress And isValidIpNumber(strArr(i))
        Next i
    End If
End Function

Private Function isValidIpNumber(strNumber As String)
    Dim ipnum As Integer
    ipnum = CInt(strNumber)
 
    isValidIpNumber = (ipnum < 256)
End Function


Private Sub cobFriendIp_Click()
    If cobFriendIp.Text = "10.167.74.175(焨墄)" Then
        ipaddress = "10.167.74.175"
        cmdConnect.Enabled = True
    ElseIf cobFriendIp.Text = "10.167.74.81(攏宒)" Then
        ipaddress = "10.167.74.81"
        cmdConnect.Enabled = True
    End If
End Sub



'帺暘偺忣曬傪弶婜壔偡傞
Private Sub pageInit()
    
    '幨恀偺僷僗
    If frmReady.i = 0 Then
        imgPath = "\img\img1.jpg"
    ElseIf frmReady.i = 1 Then
        imgPath = "\img\img2.jpg"
    ElseIf frmReady.i = 2 Then
        imgPath = "\img\img3.jpg"
    ElseIf frmReady.i = 3 Then
        imgPath = "\img\img4.jpg"
    End If
    
    '巹偺幨恀偑昞帵偝傟傑偡
    ImgMyPic.Picture = LoadPicture(App.Path & imgPath)
    '儐乕僓柤偺昞帵
    labMyName.Caption = frmReady.userName
    myName = frmReady.userName
    
End Sub

Private Sub imgGame_Click(Index As Integer)
    '儃僞儞偑巊偊傑偡
    cmdSure.Enabled = True
    If canImgCli Then
        If Index = 0 Then
            choosed = 1                    'shitou
            choosedImgPath = "\img\shi.jpg"
        ElseIf Index = 1 Then
            choosed = 2                    'jiandao
            choosedImgPath = "\img\jian.jpg"
        ElseIf Index = 2 Then
            choosed = 3                    'bu
            choosedImgPath = "\img\bu.jpg"
        End If
        imgMyChoice.Picture = LoadPicture(App.Path & choosedImgPath)
    End If
End Sub




'''''''''''''''''''''''''''''''''''''伀'''''UDP''''@InitSend@''''''伀''''''''''''''''''''''''''''''''''''''
'愙懕儃僞儞傪墴偟傑偡
Private Sub cmdConnect_Click()
    'IP偑嬻傑偨偼僼僅乕儅僢僩偑惓偟偔側偄堎忢傪張棟偟傑偡
    On Error GoTo ipError
        '埲洈曽揑IP抧毈嵟屻堦慻壛忋1000嶌堊懳曽揑抂岥
        With Winsock
            .RemoteHost = ipaddress
            Dim RemotePort() As String
            'ip傾僪儗僗傪Split偱暘妱偡傞
            
            RemotePort = Split(ipaddress, ".")
            .RemotePort = (1000 + RemotePort(3))
        End With
        MsgBox "愙懕梫媮偺憲怣偵惉岟偟傑偟偨"
        Winsock.SendData "@InitSend@" & myName & "@" & imgPath
        
        cmdSend.Enabled = True
        cmdSelMsg.Enabled = True
        txtMsg.Enabled = True
    Exit Sub
ipError:
    MsgBox ("惓偟偄IP僼僅乕儅僢僩傪擖椡偟偰偔偩偝偄")
End Sub



''''''''''''''''''''''''''''''''''''''伀''''''-@GameSend@-''''''伀'''''''''''''''''''''''''''''''''''''''''
Private Sub cmdSure_Click()
    '儃僞儞偑巊偊傑偣傫
    cmdSure.Enabled = False

    game123 = game123 + 1
    Winsock.SendData "@GameSend@" & myName & "@" & choosed & "@" & choosedImgPath
    canImgCli = False
    
End Sub

''''''''''''''''''''''''''''''''''''''伀''''''-@MsgSend@-''''''伀'''''''''''''''''''''''''''''''''''''''''

Private Sub cmdSelMsg_Click()
    txtMsg.Text = cmdSelMsg.Text
End Sub

Private Sub cmdSend_Click()
    If txtMsg.Text <> "" Then
        txtOutPut.Text = txtOutPut.Text & "---巹偼---" & vbCrLf
        txtOutPut.Text = txtOutPut.Text & txtMsg.Text & vbCrLf
      
         Dim tempstr As String
        '幄憲徚懅帪岓丆攃杮曽揑name幄憲媼洈曽
        '埲曋墬妯洈曽抦摴惀扤幄樢揑徚懅
    
        Winsock.SendData "@MsgSend@" & myName & "@" & txtMsg.Text
     
        txtMsg.Text = ""
        cmdSelMsg.Text = ""

    Else
        MsgBox "儊僢僙乕僕偼嬻偵偱偒傑偣傫"
    End If
       
End Sub



''''''''''''''''''''''''''''''''''''伀'''''Winsock_DataArrival''''''伀'''''''''''''''''''''''''''''''''''

'UDP儊僢僙乕僕庴怣張棟
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
    Dim strData        As String
    Dim strDatas()     As String
    Dim strDataTxt     As String
    Dim strDataName    As String
    Dim strDataImgPath As String
    Dim strDataChoPath As String
    Dim strDataFriChoe As String
    Dim strGame        As String
    '僨乕僞傪庴怣偡傞
    Winsock.GetData strData

    If InStr(strData, "@InitSend@") Then
       'MsgBox "---------friend picture and name----------"
        MsgBox "偁側偨偺桭払偑棃傑偟偨"
        strDatas = Split(strData, "@")
        strDataName = strDatas(2)
        strDataImgPath = strDatas(3)
        labFriendName.Caption = strDataName
        ImgFriPic.Picture = LoadPicture(App.Path & strDataImgPath)
        
    ElseIf InStr(strData, "@GameSend@") Then
        game123 = game123 + 1
        strDatas = Split(strData, "@")
       ' MsgBox "---------shiitou---jiandao---bu----------"
        strDataFriChoe = strDatas(3)
        strDataChoPath = strDatas(4)
        imgFriChoice.Picture = LoadPicture(App.Path & strDataChoPath)
        
        If game123 = 2 Then
            strGame = choosed & strDataFriChoe
            Select Case strGame
                Case "11"
                    MsgBox "堷偒暘偗"
                Case "12"
                    MsgBox "偁側偨偺彑偪偱偡"
                Case "13"
                    MsgBox "偁側偨偺晧偗偱偡"
                Case "21"
                    MsgBox "偁側偨偺晧偗偱偡"
                Case "22"
                    MsgBox "堷偒暘偗"
                Case "23"
                    MsgBox "偁側偨偺彑偪偱偡"
                Case "31"
                    MsgBox "偁側偨偺彑偪偱偡"
                Case "32"
                    MsgBox "偁側偨偺晧偗偱偡"
                Case "33"
                    MsgBox "堷偒暘偗"
            End Select
            canImgCli = True
            game123 = 0
        End If
        
        
    ElseIf InStr(strData, "@MsgSend@") Then
       ' MsgBox "----------@MsgSend@---------"
        strDatas = Split(strData, "@")
        strDataName = strDatas(2)
        strDataTxt = strDatas(3)
        
        txtOutPut.Text = txtOutPut.Text & "---" & strDataName & "---" & vbCrLf
        txtOutPut.Text = txtOutPut.Text & strDataTxt & vbCrLf

    End If
End Sub



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Unload Me
    '嵟屻偺夋柺昞帵
    frmBye.Show
End Sub






















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值