| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 530 人关注过本帖
标题:VB.net socket 互相传递文件会出现目标机器积极拒绝的错误?
只看楼主 加入收藏
zhangzhen
Rank: 2
等 级:论坛游民
帖 子:92
专家分:27
注 册:2011-3-4
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
VB.net socket 互相传递文件会出现目标机器积极拒绝的错误?
我想做一个互发文件的程序,假设A机器与B机器互相传递程序,我的代码如下:
A机器代码
Public Class Client
    Dim My_Client As DataTS.Client
    Dim My_Server As DataTS.Server
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        My_Client = New DataTS.Client
        TimerUpdate.Interval = 200
        TimerUpdate.Start()
        btnSend.Enabled = False
        My_Client.EachPackSize = 1024
        With My_Client
            .SendFilePath = txtFile.Text
            .RemoteHostIP = txtIP.Text
            .RemoteHostPort = "3333"
            Me.Text = .SendFile()
        End With
    End Sub

    Private Sub TimerUpdate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerUpdate.Tick
        If My_Client.Progress = 100 Then
            Me.Text = "发送完成"
            btnSend.Enabled = True
            TimerUpdate.Stop()
            jieshou()
        End If
    End Sub

    Private Sub txtFile_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtFile.DragOver
        txtFile.Text = e.Data.GetData(DataFormats.FileDrop)(0)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'OpenFileDialog1.ShowDialog()
        OpenFileDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
        OpenFileDialog1.InitialDirectory = "F:\"
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            txtFile.Text = OpenFileDialog1.FileName
        End If
    End Sub
    Private Sub jieshou()
        My_Server = New DataTS.Server
        Timer1.Interval = 200
        Timer1.Start()
        My_Server.EachPackSize = 1024

        With My_Server
            .LocalHostIP = "121.249.204.76"
            .LocalHostPort = "13000"
            .SavePath = "E:\"

        End With

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If My_Server.Progress = 100 Then

            MessageBox.Show("完成")
            TimerUpdate.Stop()

        End If
    End Sub

End Class


B机器代码
Public Class Server
    Dim My_Server As DataTS.Server
    Dim My_Client As DataTS.Client
    Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
        My_Server = New DataTS.Server
        TimerUpdate.Interval = 200
        TimerUpdate.Start()
      
        My_Server.EachPackSize = 1024

        With My_Server
            .LocalHostIP = txtIP.Text
            .LocalHostPort = "3333"
            .SavePath = txtSave.Text
            Me.Text = .Receive()
        End With
        btnGet.Enabled = False
    End Sub


    Private Sub TimerUpdate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerUpdate.Tick
  
        If My_Server.Progress = 100 Then
            Me.Text = "接收完成"
            btnGet.Enabled = True
            Process.Start(txtSave.Text)
            jihuo()
            TimerUpdate.Stop()

        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SaveFileDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
        SaveFileDialog1.InitialDirectory = "F:\"
        If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            txtSave.Text = SaveFileDialog1.FileName
        End If
    End Sub
    Private Sub jihuo()
               My_Client = New DataTS.Client
        My_Client.EachPackSize = 1024
        With My_Client
            .SendFilePath = "F:\1.doc"
            .RemoteHostIP = "121.249.204.76"
            .RemoteHostPort = "13000"
            Me.Text = .SendFile()
        End With
    End Sub
End Class
为什么当我把A传递给B能够成功,可到B传递给A时会出现目标机器积极拒绝的错误,我实在想不通?
搜索更多相关主题的帖子: 目标 False 
2011-03-31 12:36
fily1314
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:166
专家分:1190
注 册:2007-7-18
收藏
得分:20 
看看是不是被防火墙给拦了
2011-03-31 13:48
zhangzhen
Rank: 2
等 级:论坛游民
帖 子:92
专家分:27
注 册:2011-3-4
收藏
得分:0 
以下是引用fily1314在2011-3-31 13:48:54的发言:

看看是不是被防火墙给拦了
没用的 再说了 如果是防火墙的问题,那A也不能发给B呀?
2011-03-31 15:53
zhangzhen
Rank: 2
等 级:论坛游民
帖 子:92
专家分:27
注 册:2011-3-4
收藏
得分:0 
好了,我做成功了,
  With My_Server
            .LocalHostIP = "121.249.204.76"
            .LocalHostPort = "13000"
            .SavePath = "E:\"

        End With
少了一个 Me.Text = .Receive()
2011-03-31 19:40
快速回复:VB.net socket 互相传递文件会出现目标机器积极拒绝的错误?
数据加载中...
 
   



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

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