| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 371 人关注过本帖
标题:求助  求大神帮忙把这程序转换成VC++的代码
只看楼主 加入收藏
永远紫衣
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-4-11
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
求助  求大神帮忙把这程序转换成VC++的代码
Private MaxChan As Integer


Private Sub Command1_Click()

Text1.Text = Empty

End Sub

Private Sub Command2_Click()
Command2.Enabled = False
Dim s As String
Dim i As Integer
Dim num, count As Integer

count = 0

If List1.ListCount > 0 Then
    For i = List1.ListCount - 1 To 0 Step -1
        If List1.Selected(i) = True Then
            s = Trim(List1.List(i))
            num = Val(Right(s, 1))
            tcpServer(num).SendData Text3.Text
        Else
            count = count + 1
        End If
    Next i
    If count = List1.ListCount Then
        MsgBox "您没有选择接收的对象!", vbOKOnly, "【消息提示】"
    End If
Else
     MsgBox "还没有客户端连接到服务器!", vbOKOnly, "【消息提示】"
End If

Command2.Enabled = True

End Sub

Private Sub Command3_Click()

Dim i As Integer

MaxChan = Val(Text5.Text)

For i = 1 To MaxChan - 1

    Load tcpServer(i)

Next i

tcpListen.LocalPort = Val(Text2.Text)

Text4.Text = tcpListen.LocalIP

tcpListen.Listen

Command3.Enabled = False

Shape1.BackColor = RGB(0, 255, 0)

End Sub

Private Sub Command4_Click()
Command4.Enabled = False
 
Dim i, j As Integer
Dim s As String
For i = 0 To MaxChan - 1

    If tcpServer(i).State = 0 Then

        For j = List1.ListCount - 1 To 0 Step -1
            s = Trim(List1.List(j))
            If i = Val(Right(s, 1)) Then
                List1.RemoveItem j
            End If
        Next j
    End If
Next i
Command4.Enabled = True
End Sub

Private Sub Command5_Click()

End

End Sub

Private Sub Command6_Click()
Dim i, j As Integer
Dim flag As Boolean
flag = False
If List1.ListCount > 0 Then
    For i = List1.ListCount - 1 To 0 Step -1
        If List1.Selected(i) = True Then
            s = Trim(List1.List(i))
            j = Val(Right(s, 1))
            tcpServer(j).Close
            List1.RemoveItem i
            flag = True
        End If
    Next i
    If flag = False Then
        MsgBox "您没有选择要分离的对象!", vbOKOnly, "【消息提示】"
    End If
Else
     MsgBox "还没有客户端连接到服务器!", vbOKOnly, "【消息提示】"
End If
End Sub

Private Sub tcpBusy_Close()

tcpBusy.Close

End Sub

Private Sub tcpBusy_DataArrival(ByVal bytesTotal As Long)

tcpBusy.SendData "服务器忙,请稍后再连接!"

DoEvents

End Sub

Private Sub tcpBusy_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

tcpBusy.Close

End Sub

Private Sub tcpListen_ConnectionRequest(ByVal requestID As Long)

Dim i As Integer
Dim s As String

'决定由哪一Winsock接受请求

For i = 0 To MaxChan - 1

    If tcpServer(i).State = 0 Then

    Exit For

    End If

Next i

'如果有空闲的Winsock则让其接受请求

If i < MaxChan Then
    If tcpServer(i).State = 0 Then

        tcpServer(i).Accept requestID
        
        s = tcpServer(i).RemoteHostIP
        
        List1.AddItem "IP:" & Trim(s) & "连接 " & " 通道" & Trim(Str(i))

        Exit Sub
    End If
End If

'如果所有Winsock都用完则由专门的“忙”Winsock接受请求,以免用户要求得不到响应

tcpBusy.Close

tcpBusy.Accept requestID

End Sub

Private Sub tcpListen_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

tcpListen.Close

tcpListen.LocalPort = Val(Text2.Text)

tcpListen.Listen

End Sub

Private Sub tcpServer_Close(Index As Integer)
Dim i As Integer
Dim s As String

tcpServer(Index).Close

For i = List1.ListCount - 1 To 0 Step -1
    s = Trim(List1.List(i))
    If Index = Val(Right(s, 1)) Then
        List1.RemoveItem i
    End If
Next i

End Sub

Private Sub tcpServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)

Dim s As String

Dim i As Integer

Dim s_ip As String

tcpServer(Index).GetData s

s_ip = tcpServer(Index).RemoteHostIP

If UCase(Left(Trim(s), 2)) = "PT" Then '判断是否为悄悄话,点对点方式

    If IsNumeric(Mid(Trim(s), 3, 1)) Then

    i = Mid(Trim(s), 3, 1)

    tcpServer(i).SendData "Channel " & Index & " " & Right(Trim(s), Len(Trim(s)) - 3)

    DoEvents

    End If

Else '广播方式

   For i = 0 To MaxChan - 1

   '利用winsock的State属性给所有连接在服务器上的客户发消息

   If tcpServer(i).State = 7 Then

       tcpServer(i).SendData "Channel " & Index & " " & Trim(s)

       DoEvents

   End If

   Next i

  End If

Text1.Text = Text1.Text & "Channel:" & Index & " " & "IP:" & s_ip & " " & "Data:" & Trim(s)
End Sub

Private Sub tcpServer_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

tcpServer(Index).Close

End Sub

Private Sub Text2_Change()
Dim i As Integer
For i = 1 To Len(Text2.Text)
    If Asc(Mid(Text2.Text, i, 1)) > 0 Then
Else
    MsgBox "端口号只能为数字!", vbOKOnly, "【消息提示】"
    Text2.Text = Empty
End If
Next

End Sub

Private Sub Text3_Change()
Dim i As Integer

For i = 1 To Len(Text3.Text)
    If Asc(Mid(Text3.Text, i, 1)) > 0 Then
Else
    MsgBox "发送内容只能为字符格式!", vbOKOnly, "【消息提示】"
    Text3.Text = Empty
End If
Next

End Sub

Private Sub Text5_Change()

Dim i As Integer

For i = 1 To Len(Text5.Text)
    If Asc(Mid(Text5.Text, i, 1)) > 0 Then
Else
    MsgBox "连接数量只能为数字!", vbOKOnly, "【消息提示】"
    Text5.Text = Empty
End If
Next

If Val(Text5.Text) > 10 Then
    MsgBox "本程序最多支持10个客户端!", vbOKOnly, "【消息提示】"
    Text5.Text = 10
End If

End Sub
搜索更多相关主题的帖子: count 
2014-05-07 16:43
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:10 
无法直接转换  不同语言工具之间不能一一对应翻译

最好的解决办法 是你理解源代码的精华  然后自己重新写一份

DO IT YOURSELF !
2014-05-07 17:00
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
收藏
得分:10 
回复 2 楼 wp231957
同意
2014-05-07 17:04
快速回复:求助  求大神帮忙把这程序转换成VC++的代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012468 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved