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时会出现目标机器积极拒绝的错误,我实在想不通?