Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何使TCPClient将内容发送到同一IP,但不同的位置?_Vb.net_Tcp_Tcpclient_Tcplistener - Fatal编程技术网

Vb.net 如何使TCPClient将内容发送到同一IP,但不同的位置?

Vb.net 如何使TCPClient将内容发送到同一IP,但不同的位置?,vb.net,tcp,tcpclient,tcplistener,Vb.net,Tcp,Tcpclient,Tcplistener,好的,我有这段代码,它创建了一个TCPListener和一个TCPClient,代码对我来说不起作用,我的服务器在我自己的家里,在另一台机器上,所以我把服务器软件传递给它,我试着用我的客户机连接,客户机发送请求,服务器接收它,分析它,然后把它扔回去,但是,当它抛出时,IP是相同的,因此它会再次重定向到服务器,客户端永远不会得到响应,这只会发生在TCP tho中,UDP完成任务,但我需要TCP才能工作 服务器代码: Dim Listener As New TcpListener(IPAd

好的,我有这段代码,它创建了一个TCPListener和一个TCPClient,代码对我来说不起作用,我的服务器在我自己的家里,在另一台机器上,所以我把服务器软件传递给它,我试着用我的客户机连接,客户机发送请求,服务器接收它,分析它,然后把它扔回去,但是,当它抛出时,IP是相同的,因此它会再次重定向到服务器,客户端永远不会得到响应,这只会发生在TCP tho中,UDP完成任务,但我需要TCP才能工作

服务器代码:


    Dim Listener As New TcpListener(IPAddress.Any, 8123)
    Dim Client As New TcpClient
    Dim Message As String = ""

    Dim games As New List(Of GameClass)
    Dim queue As New Dictionary(Of String, IPEndPoint)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim ListenerThread As New Thread(New ThreadStart(AddressOf Listening))
        ListenerThread.Start()
    End Sub

    Private Sub Listening()
        Listener.Start()
    End Sub

    Sub Send(msg As String, ip As IPEndPoint)
        Try
            Client = New TcpClient(ip)
            ListBox1.Items.Add("Sending: " & msg & " to: " & ip.Address.ToString)
            'Declare the Client as an IP Address. 
            'Must be in the Correct form. eg. 000.0.0.0
            Dim Writer As New StreamWriter(Client.GetStream())
            Writer.Write(msg)
            Writer.Flush()

            'Write the Message in the stream


        Catch ex As Exception
            Try
                Client = New TcpClient(New IPEndPoint(IPAddress.Parse("127.0.0.1"), ip.Port))
                ListBox1.Items.Add("Sending: " & msg & " to: " & ip.Address.ToString)
                'Declare the Client as an IP Address. 
                'Must be in the Correct form. eg. 000.0.0.0
                Dim Writer As New StreamWriter(Client.GetStream())
                Writer.Write(msg)
                Writer.Flush()
            Catch ex1 As Exception

            End Try
        End Try
    End Sub

    Sub Send(msg As String, index As Integer, ip As IPEndPoint)
        Try
            For Each item In games(index).IPAddresses
                If item.Value.Address.ToString = ip.Address.ToString Then
                Else
                    Client = New TcpClient(ip)
                    'Declare the Client as an IP Address. 
                    'Must be in the Correct form. eg. 000.0.0.0
                    Dim Writer As New StreamWriter(Client.GetStream())
                    Writer.Write(msg)
                    Writer.Flush()
                End If
            Next


        Catch ex As Exception
            Try
                Client = New TcpClient(New IPEndPoint(IPAddress.Parse("127.0.0.1"), ip.Port))
                ListBox1.Items.Add("Sending: " & msg & " to: " & ip.Address.ToString)
                'Declare the Client as an IP Address. 
                'Must be in the Correct form. eg. 000.0.0.0
                Dim Writer As New StreamWriter(Client.GetStream())
                Writer.Write(msg)
                Writer.Flush()
            Catch ex1 As Exception

            End Try
        End Try
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Listener.Pending = True Then
            Message = ""
            Client = Listener.AcceptTcpClient()

            Dim Reader As New StreamReader(Client.GetStream())
            While Reader.Peek > -1
                Message = Message + Convert.ToChar(Reader.Read()).ToString
            End While
            Parse(Message, Client.Client.RemoteEndPoint)
        End If

    End Sub
任何建议,请,如果它是重复的,请链接到另一个帖子,我甚至没有在谷歌上问这个词